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

#1 2010-08-06 21:10:15

JeanTheFox
Scratcher
Registered: 2010-06-14
Posts: 1000+

How to make a simple gravity script

Lots of people are asking how to make a simple platformer, so here it is;

Chapters

GRAVITY
SCROLLING

Gravity

Method 1:
Make a sprite called "Ground".
Now give the main sprite this script;

http://i36.tinypic.com/2zs8fn9.png

You will notice that your sprite will now seem to have a gravitational pull.

Method 2:
Make another sprite called "sensor". It should be about the width of your main sprite.
Give your sensor these scripts;

http://i37.tinypic.com/qywzuh.png
http://i33.tinypic.com/ogmij8.png

I used change y by -55 because that way the sprite would just be touching the ground. It does not always have to be y -55.  smile

If you think that your sprite is falling to fast or too slow, increase or decrease the number in the "change y by []" block, respectively.

Scrolling

Scrolling is harder; it includes longer scripts.
This is a compact method;

Make two sprites that are background size. Name them background1 and background2.
Give background1 this script:
http://jeans-random-site.yolasite.com/resources/Untitled3.png
Give background2 this script:
http://jeans-random-site.yolasite.com/resources/Untitled4.png
And give the stage this script:
http://jeans-random-site.yolasite.com/resources/Untitled5.png

Last edited by JeanTheFox (2010-08-07 18:07:21)


http://i51.tinypic.com/20gcn5j.png

Offline

 

#2 2010-08-06 21:23:50

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How to make a simple gravity script

Thanks for posting this tutorial. Glad to have something to point people to when they ask for platforming help. Could you consider adding a section for scrolling, since they are often used in conjunction?


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/OZn2RD3.png&link2=http://i.imgur.com/duzaGTB.png&link3=http://i.imgur.com/CrDGvvZ.png&link4=http://i.imgur.com/POEpQyZ.png&link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#3 2010-08-06 21:24:41

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: How to make a simple gravity script

I don't get the sensor xP. And for the gravity, put 3 if's inside of each other and make it change y by 1 each if. That makes it do the same thing as your gravity, but it detects to the pixel.


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#4 2010-08-06 21:36:37

JeanTheFox
Scratcher
Registered: 2010-06-14
Posts: 1000+

Re: How to make a simple gravity script

Sunrise-Moon wrote:

I don't get the sensor xP. And for the gravity, put 3 if's inside of each other and make it change y by 1 each if. That makes it do the same thing as your gravity, but it detects to the pixel.

Should I use that as another method?

Sunrise-Moon wrote:

Thanks for posting this tutorial. Glad to have something to point people to when they ask for platforming help. Could you consider adding a section for scrolling, since they are often used in conjunction?

I'll try  smile


http://i51.tinypic.com/20gcn5j.png

Offline

 

#5 2010-08-06 21:54:07

JeanTheFox
Scratcher
Registered: 2010-06-14
Posts: 1000+

Re: How to make a simple gravity script

Harakou wrote:

Thanks for posting this tutorial. Glad to have something to point people to when they ask for platforming help. Could you consider adding a section for scrolling, since they are often used in conjunction?

Done!  big_smile


http://i51.tinypic.com/20gcn5j.png

Offline

 

#6 2010-10-10 16:24:02

JeanTheFox
Scratcher
Registered: 2010-06-14
Posts: 1000+

Re: How to make a simple gravity script

(Epic) Bump!


http://i51.tinypic.com/20gcn5j.png

Offline

 

Board footer