Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to make a working gun that when fired, if it hits another sprite they disappear?
- hudo101code
- Scratcher
5 posts
how to make a working gun that when fired, if it hits another sprite they disappear?
the title is pretty long, and im sorry for that, but im just pretty curious on how i could do this. anyone have any ideas? thanks
- helloworldbyeworld
- Scratcher
1000+ posts
how to make a working gun that when fired, if it hits another sprite they disappear?
You will need 2 sprites:
1. The gun
2. The target
Make the gun have two costumes:
1. The gun costume
2. The bullet
Put this script in the gun sprite:
Put this script in the target:
1. The gun
2. The target
Make the gun have two costumes:
1. The gun costume
2. The bullet
Put this script in the gun sprite:
when green flag clicked
switch costume to [Gun v]
forever
point towards [mouse-pointer v] // mouse for rotation
if <mouse down?> then // click to fire
switch costume to [Bullet v]
create clone of [myself v] // Create bullet
switch costume to [Gun v]
wait (0.2) secs // short delay after the firing
end
end
when I start as a clone
repeat until <touching [target v] ?>
move (2) steps
wait (0.05) secs
end
broadcast [Hit v]
Put this script in the target:
when I receive [Hit v]
hide
Helloworldbyeworld | 1200+ posts
Have a great day
- wallofdaggers124356
- Scratcher
11 posts
how to make a working gun that when fired, if it hits another sprite they disappear?
You could
This will when the bullet hits whatever you want to hit it will set a variable. Then waits so that whatever you want can check if its the thing getting hit and the bullet did hit something. Finally Whatever you want to Go away does that Depending if its a clone or a sprite.
- ~When I start as clone~
Point towards mouse
Forever{
Move (x) steps
if <Touching (Sprite you want to Disappear)> {
Set Shot hit to 1
Wait 0.5 seconds
Delete this clone
}
}
And in the Clone Code
When I start as clone/ When Green flag clicked.
Forever {
Whatever the clone does
If <Touching Bullet> & <Shot hit = 1> {
Set Shot Hit to 0
Delete this clone/hide & Stop this script
}
This will when the bullet hits whatever you want to hit it will set a variable. Then waits so that whatever you want can check if its the thing getting hit and the bullet did hit something. Finally Whatever you want to Go away does that Depending if its a clone or a sprite.
- hudo101code
- Scratcher
5 posts
how to make a working gun that when fired, if it hits another sprite they disappear?
AWESOME, thanks so much bro!
Last edited by hudo101code (Dec. 7, 2021 02:36:20)
- hudo101code
- Scratcher
5 posts
how to make a working gun that when fired, if it hits another sprite they disappear?
Thanks man, appreciate it
- adem_1000
- Scratcher
84 posts
how to make a working gun that when fired, if it hits another sprite they disappear?
you can use this but you need 2 coustumes the bullet and the gun the title is pretty long, and im sorry for that, but im just pretty curious on how i could do this. anyone have any ideas? thanks
forever
switch costume to [gun v]
if <mouse down?> then
create clone of [myself v]
end
end
when I start as a clone
switch costume to [bullet v]
repeat until <<touching [edge v] ?> or <touching [something v] ?>>
move (10) steps
end
delete this clone
- Discussion Forums
- » Help with Scripts
- » how to make a working gun that when fired, if it hits another sprite they disappear?