Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » bullets take damage too
- forkmanb
-
Scratcher
100+ posts
bullets take damage too
https://scratch.mit.edu/projects/946021761/
(press A to summon a UFO, this game is WIP so bullets don't make you take damage)
when you summon a UFO, it shoots bullets at you. because I made a script that prevents the BULLETS from taking damage instead of the UFO, the bullets… pass right though the UFO. That's because I have a script like this:
Inside the Bullet sprite:
(I hope this doesn't sound confusing. I can clarify, I'm just really bad at explaining things.)
(press A to summon a UFO, this game is WIP so bullets don't make you take damage)
when you summon a UFO, it shoots bullets at you. because I made a script that prevents the BULLETS from taking damage instead of the UFO, the bullets… pass right though the UFO. That's because I have a script like this:
Inside the Bullet sprite:
when I start as a clonehowever, this doesn't seem to work since the UFO is a clone. As a result, it makes the bullets pass through the UFO. So in short; how would I make one clone detect another sprite's clone's variable (to see if it's a main clone or a bullet)?
forever
if <touching [UFO v] ?> then
if <([UFO Index v] of [UFO v]) = [1]> then // if a UFO clone's Index is 1, that means that it's a UFO, not a bullet
wait (0.0001) secs
delete this clone
end
end
(I hope this doesn't sound confusing. I can clarify, I'm just really bad at explaining things.)
Last edited by forkmanb (Jan. 4, 2024 02:54:20)
- PhiPhenomenon
-
Scratcher
500+ posts
bullets take damage too
Your project is not shared.
It seems like it would be much simpler to have the bullets as a separate sprite from the UFO. This way, each UFO can clone the bullets and you don't have to go through all the trouble of assigning a UFO clone index.
It seems like it would be much simpler to have the bullets as a separate sprite from the UFO. This way, each UFO can clone the bullets and you don't have to go through all the trouble of assigning a UFO clone index.
- deck26
-
Scratcher
1000+ posts
bullets take damage too
So are you saying you want the UFOs to take damage from bullets but the bullets should not take damage? Surely you can tell the difference between them by looking at the costume so I can't see how the UFO index of UFO is going to help - that can only repost the value of that variable for the sprite, never for a clone.
- forkmanb
-
Scratcher
100+ posts
bullets take damage too
sorry, just posted the project now.
PhiPhenomenon's suggestion is great, but I don't know how to make the UFO bullets (as a clone) spawn at the UFO (as a clone) ‘s location.
to deck26: I want the UFOs to take damage from YOUR bullets, but I don’t want the UFO bullets to take damage. This is a problem because both (the UFO bullets and the UFO itself) are clones of the same sprite, so I don't know how to make YOUR bullets differentiate the actual UFO and the UFO's bullets.
PhiPhenomenon's suggestion is great, but I don't know how to make the UFO bullets (as a clone) spawn at the UFO (as a clone) ‘s location.
to deck26: I want the UFOs to take damage from YOUR bullets, but I don’t want the UFO bullets to take damage. This is a problem because both (the UFO bullets and the UFO itself) are clones of the same sprite, so I don't know how to make YOUR bullets differentiate the actual UFO and the UFO's bullets.
- PhiPhenomenon
-
Scratcher
500+ posts
bullets take damage too
PhiPhenomenon's suggestion is great, but I don't know how to make the UFO bullets (as a clone) spawn at the UFO (as a clone) 's location.Here are my scripts for the UFOs:

Here are my scripts for the bullets:

Basically, to track the UFO clone location, we set two global variables (cloneBulletX and cloneBulletY) to the cloned UFO's coordinates. Then, we send a broadcast. The bullet receives it and goes to the cloning location set by the variables.
Lastly, we need a this sprite only variable (@isMain). We need to determine if the bullet cloning is the original sprite because clones may also receive this broadcast and create more bullet clones than intended.
Here's what the script does, with the cats being the UFOs and shooting four bullets after spawning:

- forkmanb
-
Scratcher
100+ posts
bullets take damage too
wait, what if two UFOs were firing at the same time?
- PhiPhenomenon
-
Scratcher
500+ posts
bullets take damage too
wait, what if two UFOs were firing at the same time?Scratch gives the illusion of running scripts at the same time. However, the scripts run in the same frame, so they still maintain their order, though they look like two things are updated at once. So it's not a problem.
Two UFOs that fire in the same frame will still have one UFO that clones the bullets first. So the cloning broadcast should still run with the specific UFO that needs bullets cloned.
- deck26
-
Scratcher
1000+ posts
bullets take damage too
One option might be to hide the UFO bullets at the start of the frame so they are not detected by your bullets. You can then show them and detect what they are hitting once you've dealt with your bullets. What the player sees is what is showing at the end of the frame so they won't see this happening.
- deck26
-
Scratcher
1000+ posts
bullets take damage too
https://scratch.mit.edu/projects/947269511/ is a quick example of what I meant. All detection is via touching sprite blocks but only the red apples take a hit even though the green apples are clones of the same sprite.
- forkmanb
-
Scratcher
100+ posts
bullets take damage too
sorry, I've been using PhiPhenomenon's strategy, and so far, it works.
But… there's two problems.
1) The bullets shoot in the wrong direction, and
2) The UFO doesn't take damage.
How do I fix this?
But… there's two problems.
1) The bullets shoot in the wrong direction, and
2) The UFO doesn't take damage.
How do I fix this?
- PhiPhenomenon
-
Scratcher
500+ posts
bullets take damage too
Sorry for the late response.
1) The bullets shoot in the wrong directionYour code only updates the UFO dir variable once, which is when the clone is initialized. The clone points towards the player every two seconds, so you need to move the UFO dir set block to inside the loop.
2) The UFO doesn't take damage.That's because you set the UFO index for clones to be 0, but you're checking if it's equal to 1 to take damage from bullets.
Last edited by PhiPhenomenon (Jan. 7, 2024 03:18:58)
- forkmanb
-
Scratcher
100+ posts
bullets take damage too
oh my goodness, this has changed everything. thanks a lot for the help.
- Discussion Forums
- » Help with Scripts
-
» bullets take damage too


