This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-14 21:12:28

krestivo
Scratcher
Registered: 2009-03-18
Posts: 3

Simple ball-bouncing physics?

I'm looking for a simple example of how to do ball-bouncing, including the bounces at the end when it hits the ground, or change of rotation when it hits a wall. Simulations of gravityy, etc. I've seen some complex examples but I don't really understand how they work.

Offline

 

#2 2011-07-14 22:13:17

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Simple ball-bouncing physics?

Have a look at this and see if it helps...

http://scratch.mit.edu/projects/Ratty1967UK/1207378

Offline

 

#3 2011-07-14 23:44:59

Thescratch3
Scratcher
Registered: 2011-06-14
Posts: 1000+

Re: Simple ball-bouncing physics?

Well why need to go to that link? (No offense) But there is a faster way. Just go to the Scratch program open Scratch, click file, click open, click examples, click Pong, take a look at their scripts and *drum roll* you have it!


View my projects. Or face The scratch curse! (Get it?)
http://i56.tinypic.com/2cdk8hy.png

Offline

 

#4 2011-07-18 17:32:22

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Simple ball-bouncing physics?

none taken  smile  although the Pong example doesn't mimic the effects of gravity...well, not on my planet! hehehe

Offline

 

#5 2011-07-18 23:06:05

Flait7
Scratcher
Registered: 2008-04-14
Posts: 100+

Re: Simple ball-bouncing physics?

If you want gravity to be applied to the ball, tell it to decelerate 9.8m/s, which is approximately the effect of gravity, you can unify each step to be a meter, making it 9.8 steps a second, then divide that by around 30 to make it slow by about 0.327 steps a frame (I might be wrong, I'm just assuming that scratch runs at 30fps).

<forever>
<change{ y velocity }by( -0.327 )
<if on edge, bounce>

^That I think would mimic the constant pull of gravity.
Use the variable Y velocity, or another variable with a different name to tell how many steps the sprite will move, and use <change y by( <{ y velocity }> for the motion of the sprite you're going to make move, it'll move on the up/down or y axis at the speed that will be effected by gravity.

For hitting the ground try

<if><touching[ ground ]>
<point in direction( (( 180 <-> <direction> ))

and for a wall, try

<if><touching[ wall ]>
<point in direction( (( 0 <-> <direction> ))

I hope this helps!

Last edited by Flait7 (2011-07-18 23:08:37)


http://scratch.mit.edu/static/projects/Flait7/2248016_sm.pnghttp://scratch.mit.edu/static/projects/Flait7/1827934_sm.png

Offline

 

#6 2011-07-19 13:42:55

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: Simple ball-bouncing physics?

I made a small project to do exactly what you want, at least, to my understanding. You can view it here: http://scratch.mit.edu/projects/demosthenes/556255.

If you have any questions, feel free to ask, preferably by commenting on the project, that way, I will get a notification.


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

Board footer