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

#1 2010-05-10 17:55:51

Nick60
Scratcher
Registered: 2007-06-17
Posts: 100+

Tutorial: How to Implement Gravity

Gravity is quite simple to create or mimic in Scratch - this short code snippet will show you how to implement it.

Look at this picture and this will show you how to implement gravity onto your sprite.

You will also have to declare one variable (in this example it's identified as setY).

http://img200.imageshack.us/img200/9058/81675378.png

Things to consider: 

- Ground is set by the color Cyan (light blue) as indicated by the touching color block.    You can set ground as a sprite or anything else.

- Movement (this is only up and down)

If you have problems making your character move left and right (even while you are jumping, then take a look at this other example I've kindly created for your convenience.   

If you implement this, it will create smooth movement (even while jumping, you can still move around).

http://img100.imageshack.us/img100/9537/86162345.png

Last edited by Nick60 (2010-05-10 18:07:46)


Let's  Be Blue!

Offline

 

#2 2010-05-10 17:58:41

mikey1105
Scratcher
Registered: 2010-03-22
Posts: 39

Re: Tutorial: How to Implement Gravity

Wow, this actually (Somehow) seems a bit more easy to understand than the other, I can tell script from script. Thanks!

Offline

 

#3 2010-05-10 18:08:50

Nick60
Scratcher
Registered: 2007-06-17
Posts: 100+

Re: Tutorial: How to Implement Gravity

No problem.  By the way, I've updated the code snippets with an even simpler way of doing things.  Also, made another example for those who have trouble with movement (left and right).


Let's  Be Blue!

Offline

 

Board footer