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

#1 2009-11-09 14:14:05

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

How Do I Make Gravity for a platformer ?

hi , I'm making a BMX game and i don't no how to make gravity.
Any suggestions ?

thanks
TRWinner  smile


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#2 2009-11-09 14:23:22

RHY3756547
Scratcher
Registered: 2009-08-15
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

hi , I'm making a BMX game and i don't no how to make gravity.
Any suggestions ?

thanks
TRWinner  smile

To make gravity you need to make a variable called Yvelocity. Once you have done so put this at the start of a forever loop:

[blocks]<change{ Yvelocity }by( HowStrongYouWantTheGravityToBe[/blocks]

The gravity strength must be Negative or the Object will float upwards. Next - put this in with the movement for your object:

[blocks]<change y by( <{ Yvelocity }>[/blocks]

Remember that collision when working with gravity can get quite complicated. There are many tutorials on how to do accurate collision about the scratch site.

Offline

 

#3 2009-11-10 08:39:25

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

Thanks,
were could I find anything on collisions?

cheers
TRWinner  smile


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#4 2009-11-10 08:42:01

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

One way is to have color sensing collision.

If <touching color[black]>      <----Make the platforms black
Set yvelocity to (-1*gravity)     <-----This way it counter-acts the gravity, because X+(-1*X)=0

When it gets complicated, this isn't always the best method. But if you want to use this method, I reccomend having green grass, and on the top of the grass is a short layer of darker green, and instead of sensing black, it senses the dark green.

Last edited by Lucario621 (2009-11-10 08:42:53)


http://i.imgur.com/WBkM2QQ.png

Offline

 

#5 2009-11-10 09:07:49

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

sorry can you say that a bit simpler for me,
coz I'm a bit of a sub-zero moron  roll

cheers
TRWinner


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#6 2009-11-10 09:12:25

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

sorry can you say that a bit simpler for me,
coz I'm a bit of a sub-zero moron  roll

cheers
TRWinner

Lol

<if><touching color[ color of ground ]>
<set{ yvelocity }to( ((-1  <*> <{ gravity }> ))

Last edited by Lucario621 (2009-11-10 09:13:25)


http://i.imgur.com/WBkM2QQ.png

Offline

 

#7 2009-11-10 09:27:05

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

thanx loads.
how could I make tilt?, i.e going up a ramp

thanx
TRWinner  smile


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#8 2009-11-10 09:33:59

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

thanx loads.
how could I make tilt?, i.e going up a ramp

thanx
TRWinner  smile

Hmm, that would be a bit tricker, as it would require and such, so I'm not sure if you would be ready for that, but there are some common ways to go up a ramp, not neccecarily tilting:

Instead of the previous blocks, have this:

<if><touching color[ color of ground ]>
<set{ yvelocity }to( ((-2  <*> <{ gravity }> ))

Instead of -1 I have -2. That should work, I think.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#9 2009-11-10 09:34:44

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

Lucario621 wrote:

TRWinner wrote:

sorry can you say that a bit simpler for me,
coz I'm a bit of a sub-zero moron  roll

cheers
TRWinner

Lol

<if><touching color[ color of ground ]>
<set{ yvelocity }to( ((-1  <*> <{ gravity }> ))

whats "gravity" mean in that script?


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#10 2009-11-10 09:39:16

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

Try using the scripts from this project
http://scratch.mit.edu/projects/archmage/145760


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#11 2009-11-10 09:45:29

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

archmage wrote:

Try using the scripts from this project
http://scratch.mit.edu/projects/archmage/145760

Yeah thats a good example, thats probably what you want.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#12 2009-11-10 10:42:12

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

Thanx - but I changed the costume of player to a BMXer
and it wouldn't go past terrain 2 ?  hmm

Any thoughts ?


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#13 2009-11-10 11:12:24

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

Thanx - but I changed the costume of player to a BMXer
and it wouldn't go past terrain 2 ?  hmm

Any thoughts ?

Ohh... you're making a biking/racing game... well that changes everything. Then you really should use sensors and tilting. I'll try to find something for ya'.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#14 2009-11-10 11:17:44

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

how do you put signatures on your post ?


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#15 2009-11-10 11:42:38

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

follow this tutorial to add more terrain sprites http://scratch.mit.edu/forums/viewtopic.php?id=2440


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#16 2009-11-10 11:46:19

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

how do you put signatures on your post ?

To the bottom of where it says 'Scratch Forums', it says Profile. Click on it. On the left there should be a list of options to go to. Click on Personality. Then in the text box put what you want to say. And click submit!


http://i.imgur.com/WBkM2QQ.png

Offline

 

#17 2009-11-10 12:25:58

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

Lucario621 wrote:

TRWinner wrote:

Thanx - but I changed the costume of player to a BMXer
and it wouldn't go past terrain 2 ?  hmm

Any thoughts ?

Ohh... you're making a biking/racing game... well that changes everything. Then you really should use sensors and tilting. I'll try to find something for ya'.

can i make it tilt ,or is that to much for a sub-zero moron lik me, should i just forget this whole thing and do something else?

oh and thanks for telling me about signatures.


cheers TRWinner  smile


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#18 2009-11-10 12:28:29

TRWinner
Scratcher
Registered: 2008-10-08
Posts: 9

Re: How Do I Make Gravity for a platformer ?

ps i want to finish this one


http://www.scratchblox.myadopts.com/get/11.gif

Offline

 

#19 2009-11-10 12:57:35

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

Why do you keep calling yourself a sub-zero moron. I don't even know what it is.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#20 2009-11-10 15:30:04

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How Do I Make Gravity for a platformer ?

TRWinner wrote:

Lucario621 wrote:

TRWinner wrote:

Thanx - but I changed the costume of player to a BMXer
and it wouldn't go past terrain 2 ?  hmm

Any thoughts ?

Ohh... you're making a biking/racing game... well that changes everything. Then you really should use sensors and tilting. I'll try to find something for ya'.

can i make it tilt ,or is that to much for a sub-zero moron lik me, should i just forget this whole thing and do something else?

oh and thanks for telling me about signatures.


cheers TRWinner  smile

Don't bother with tilting at this point. Just modify that example project I posted.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer