Discuss Scratch

lightning1997
Scratcher
6 posts

If touching sprite bounce script

Can someone tell me how to make a block like a “if on edge bounce” but it's for a sprite?
TheAnomalousPseudo
Scratcher
1000+ posts

If touching sprite bounce script

To clarify: you want a sprite that is moving of its own accord to reflect off a surface and keep moving? Or do you just want collisions?
lightning1997
Scratcher
6 posts

If touching sprite bounce script

TheAnomalousPseudo wrote:

To clarify: you want a sprite that is moving of its own accord to reflect off a surface and keep moving? Or do you just want collisions?
I want it to reflect off a sprite
TheAnomalousPseudo
Scratcher
1000+ posts

If touching sprite bounce script

Assuming that you are always colliding with vertical walls, this works:

forever
wait until <touching [wall v] ?>
point in direction ((direction) * (-1))
wait until <not<touching [wall v]?>>
end

If you need to take into account the angle of the surface, let me know.
lightning1997
Scratcher
6 posts

If touching sprite bounce script

TheAnomalousPseudo wrote:

Assuming that you are always colliding with vertical walls, this works:
If you need to take into account the angle of the surface, let me know.

Yeah i do
cs345375567
Scratcher
53 posts

If touching sprite bounce script

this is a script from my pong game and it only works on flat edges and no diagonals or curves
(x velocity) // make x velocity and y velocity variables
(y velocity)

when flag clicked // if you want it to do specific x and y velocity then delete the sin of and cos of blocks and make them numbers
set [x velocity v] to ([sin v] of (direction))
set [y velocity v] to ([cos v] of (direction))
forever
change x by (x velocity)
if <touching (sprite v) ?> then
set [x velocity v] to ((x velocity) * (-1))
change x by (x velocity)
end
change y by (y velocity)
if <touching (sprite v) ?> then
set [y velocity v] to ((y velocity) * (-1))
change y by (y velocity)
end
end
deck26
Scratcher
1000+ posts

If touching sprite bounce script

https://scratch.mit.edu/projects/99412537/ shows the calculation to get the bounce angle for a known surface angle and angle of approach.

Powered by DjangoBB