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

#1 2010-02-26 16:47:20

DanDarra
Scratcher
Registered: 2010-02-23
Posts: 1

Gravity effect

Hi im new and gained an understanding, but how can i apply gravity effects to a sprite, so in school i was messing about with a hang glider and these naturally want to fall down, how can i get an object to naturally fall but still have full control over the sprite to allow to move "up" again,
also for games like "kitty cannon" where you fire an object and see how far they travel, but i cant make to object fall back down again.
Thanks

Offline

 

#2 2010-02-26 23:58:26

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Gravity effect

For simple gravity, just make it change y by -1, unless it is touching the mouse and the mouse is down (it is being dragged), or it is touching the bottom.

For realistic gravity, you'll need to create a variable. Just keep changing this variable by 1, and moving down by some squared relationship of it, such as:
<forever>
|<if><< << <mouse down?> <and> <touching[ mouse ]> >> <or> <touching[ edge ]> >>
||<set{ n }to( 0 )>
|<else>
||<change{ n }by( 1 )>
||<change y by( (( <{ n }>((  <*> <{ n }> )) <*> -1 )) )>
|<end>
<end>
The -1 can be increased or decreased to simulate a greater or lesser mass/wind resistance. (It must be negative, though; other wise, it will fall up!)

Note also that this simulates an object falling through a vacuum; the more complex aerodynamic calculations needed to let it reach a terminal velocity are redundant, given the height of the screen.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

Board footer