Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » bullets
- richardnichols
-
New Scratcher
23 posts
bullets
hi, how can i make a bullet hit the wall and both the bullet and the wall disappears? like a sprite fires a gun and the bullet comes out and hits the wall so both the bullet and the wall disappears.
- richardnichols
-
New Scratcher
23 posts
bullets
yes but if i use it only one of them disappears and i want both to disappear.
- AonymousGuy
-
Scratcher
1000+ posts
bullets
yes but if i use it only one of them disappears and i want both to disappear.Oh that is because of scratch execution times and stuff and how Flash Player is line-by-line blah blah blah…
Anyways to fix it do this:
when gf clicked //Put this script in bullet
show
forever
if <touching [wall v]> then
wait (0.1) secs //To allow wall to recognize it
hide
end
end
when gf clicked //Put this script in wall
show
forever
if <touching [bullet v]> then
wait (0.1) secs //To allow bullet to recognize it
hide
end
end
- AonymousGuy
-
Scratcher
1000+ posts
bullets
oh thats very helpful. thank you very much!You're welcome!

- JsnPrkr
-
Scratcher
100+ posts
bullets
Does each sprite check if it's touching the other sprite?
Depending on the timing of each sprite's script, if the bullet knows it hit the wall, it can hide itself and the wall can do the same. However, if the bullet hides and THEN the wall tries to check if it's touching the bullet, the Touching event never happens for the wall.
Which one disappears in your project?
Depending on the timing of each sprite's script, if the bullet knows it hit the wall, it can hide itself and the wall can do the same. However, if the bullet hides and THEN the wall tries to check if it's touching the bullet, the Touching event never happens for the wall.
Which one disappears in your project?
Last edited by JsnPrkr (Jan. 4, 2014 06:22:36)
- AonymousGuy
-
Scratcher
1000+ posts
bullets
Does each sprite check if it's touching the other sprite?Well the reason for the glitch is the scratch player can only execute one block at a time, so you have to make the sprite wait to allow the other sprite to realize its there. If you hide the sprite then the other one can't detect that it is there when the scratch executor comes to its detection script.
Depending on the timing of each sprite's script, if the bullet knows it hit the wall, it can hide itself and the wall can do the same. However, if the bullet hides and THEN the wall tries to check if it's touching the bullet, the Touching event never happens for the wall.
Which one disappears in your project?
- JsnPrkr
-
Scratcher
100+ posts
bullets
If you hide the sprite then the other one can't detect that it is there when the scratch executor comes to its detection script.
Is that not what I said?
Depending on the timing of each sprite's script, if the bullet knows it hit the wall, it can hide itself and the wall can do the same. However, if the bullet hides and THEN the wall tries to check if it's touching the bullet, the Touching event never happens for the wall.
When helping someone, it's good to find out what they've tried so they can learn from their efforts. There's more than one way to create the described behavior. Also better to teach someone to fish than hand them one, yes?
Last edited by JsnPrkr (Jan. 4, 2014 06:35:03)
- Discussion Forums
- » Help with Scripts
-
» bullets




