Discuss Scratch

vinians
New to Scratch
20 posts

Bouncing how?

Hi guys! I know I can bounce when the sprite hit boundary but how can I bounce when my sprite hit a wall for example? What formula can I use for it?
scubajerry
Scratcher
1000+ posts

Bouncing how?

http://scratch.mit.edu/projects/12004820/

You will just me messing with the X parameters instead of the Y

You can make the wall part of the backdrop, or a sprite.

Last edited by scubajerry (Oct. 11, 2013 15:28:58)

vinians
New to Scratch
20 posts

Bouncing how?

Its not that simple… I need a way to bounce accord to the angle like a mirror reflexion of a laser!

see in “dl.dropboxusercontent.com/u/16702799/images/bounce.png”

My wall is a sprite already, but I want my another sprite bounce when collide with wall sprite, I know theres a calculation but I dont remember !
scubajerry
Scratcher
1000+ posts

Bouncing how?

If you are moving in a direction, set the new direction ito 180-direction

If you are using Y velocity and X velocity you do it like this http://scratch.mit.edu/projects/13152873/

Last edited by scubajerry (Oct. 11, 2013 15:52:23)

vinians
New to Scratch
20 posts

Bouncing how?

Thanks I will try !
scubajerry
Scratcher
1000+ posts

Bouncing how?

Are you drawing the path, or just having an object bounce?
vinians
New to Scratch
20 posts

Bouncing how?

Just an object fired by a cannon which sometime will bounce against a wall, Im using direction.
Thanks!
scubajerry
Scratcher
1000+ posts
pedro_pete
Scratcher
4 posts

Bouncing how?

Do you want to assume perfect bounciness (no loss of speed)?
Locomule
Scratcher
1000+ posts

Bouncing how?

It was fine on my pc. I made the ball speed ajustable. If it leaves the box, restart it and slow it down 1 speed. Eventually it should run fine. The point is that the method works. I could have made the wall thicker but I wanted to prove that the system works on its own.

Likewise, if you start it and the ball stays inside, try speeding it up. I made it deafault to 6 which is half as fast as my pc will run it correctly.
Locomule
Scratcher
1000+ posts

Bouncing how?

ps. Most Scratch problems do not have a bulletproof solution. If I increase the ball speed too much, I will have to increase the wall thickness, add more check loops, or maybe use a different method, like using 4 sprites for the walls. Or adding a feeler sprites. Or backing the ball up after contact, etc. Even the most stable method may have to be replaced or altered as your project grows.

Powered by DjangoBB