Discuss Scratch

Drillem1
Scratcher
12 posts

Clones being hit by bullet

I’m making a project where you can shoot bullets at enemies which are all clones. I have the separate health working but I can’t seem to figure out a way to make the bullet only able to hit one enemy. It hits multiple if they group up. How could I fix this? I looked on this forum and found a post with the same question, but the projects they made that solved the issue have since been removed, so I'm looking to open up discussion about it again. Thanks!
qwertycodechamp90411
Scratcher
100+ posts

Clones being hit by bullet

Does deleting the bullet when it damages a clone work?

Useful Links: Text Generator ——— Encoders/Decoders (Normal, Case Sensitive) ——— New Math Blocks ——— Comment what next on my profile!
Wait, we’re at 900 million projects? So close to 1 billion projects uploaded to the server!

<((x) ^ ((1) / (y))::operators) = ((y) √ (x)::operators)> // is false if x < 0???
Hi! I'm qwertycodechamp90411. I'm most active on the suggestions forum and the help with scripts forum, because I like to help other people and improve scratch! I like to think I'm good at scratch, but there's a lot I don't know/understand (how on earth do scrolling platformers work lol). As a general rule of thumb, I should have the answer if it's math related, because I'm a very stereotypical nerd when it comes to math.
Drillem1
Scratcher
12 posts

Clones being hit by bullet

Not exactly. Because the enemies can be on the same x value as they move, the fireball could hit both their x values at the same time and damage multiple of them when it shouldn't
P-P-C
Scratcher
21 posts

Clones being hit by bullet

Try making lists that store the x and y coordinate and the life of clones, then when the bullet hit one of them , it go at each pos of these list and check if the distance between the ball and the ennemy is less than the radius of the ennemy + the radius of the ball. When it is the case , you increment the life of this clone by -1 .
This work if all ennemy are circle , if they are square , you 'll need to add some trigonometry to find the distance between the center of the square and the edge of the square proportional to the angle of incidence of the bullet
This also fix the problem of two bullet touching a same ennemy and doing only one point of damage
P-P-C
Scratcher
21 posts

Clones being hit by bullet

Nevermind, if it is a square just check If delta x and delta y are less than the size of the square
WhyteTIGER
Scratcher
16 posts

Clones being hit by bullet

You can make a variable “Enemyhit” and each time the bullet is fired it sets to 0
When enemy gets hit then the variable changes to 1


set [Enemyhit] to [0]
if <Enemy got hit> then
set [Enemyhit] to [1]
end

Now for each clone:
if  <[Enemyhit] = [0]> then
change [clonelives] by (-1)
end

This should make it so that when a bullet hits the enemy it can't do damage again

I hope this helped you! If you have any other questions please ask.

Hey there!
I've been active on scratch for almost 5 years on different accounts. I enjoy creating, coding and sharing good quality projects and helping others with their code
My top 3 best projects:
1. HYPERCAR RACING
2. CUBLOX
3. FLAPPY BIRD - Mobile Friendly Remake

Powered by DjangoBB