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

#1 2007-10-27 19:03:48

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Need a tutorial on gravity.

I need a tutorial on how to make your char jump. And then after he's done fall to the ground and make sure he doesn't go through the ground...And maybe a a tutorial on how to switch sprites so it looks like your character is walking. Can some on tell me where I might find tutorials like these?

Offline

 

#2 2007-10-27 19:06:34

Vanslar
Scratcher
Registered: 2007-03-17
Posts: 100+

Re: Need a tutorial on gravity.

for gravity, just look for the tag gravity and choose one, for the walking you should make different costumes and then in the scripts use... (forever)next costume   wait__sec.

Last edited by Vanslar (2007-10-27 19:06:57)


  I am a royal pain in the butt, I am ~Vanslar~       
      Want better gravity? Go to
Realistic Gravity, By Vanslar 2-D
Want a better way to spend your spare time? CubeField

Offline

 

#3 2007-10-27 19:52:30

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

Re: Need a tutorial on gravity.

To switch sprites while your enemy is walking just use the change costumes block.

I had posted a simple gravity tutorial in another tread but I guess I'll repost it with ways to make it react the the ground.


Ok people I will tell you how to implement gravity!

The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.

// First create a "this sprite only" variable on your sprite called yVelocity

Then put this script into your sprite.
// yVelocity will only change if player is not touching the ground
<when green flag clicked>
<set{  yVelocity}to(0
<forever>
<if>
<touching[ ground ]
<set{ yVelocity }to( 0
<end>
<else>
<change{ yVelocity }by(-1
<change y by( yVelocity
<end>

//Now that wasn't so hard was it?


Now to jump we invert gravity.
//The player should only jump if he is touching the ground
<when[ up ]key pressed>
<if>
<touching[ ground ]
<set{  yVelocity}to( 10
<end>


Controlling x and y velocity is an important of game design and it's good to learn about it  smile

The player should not fall though the ground but he might get stuck in it a little. To fix this the best way is to use color sensing. So if the color of the upper part of the sprites is touching the color in the ground make the sprite rise.

Last edited by archmage (2007-10-27 20:12:17)


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

 

#4 2007-10-27 21:30:42

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Re: Need a tutorial on gravity.

Thanks but im stuck on the first one on change Y by yVelocity there's only change y by "number"....Can you help me out?

Offline

 

#5 2007-10-27 23:03:34

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

Re: Need a tutorial on gravity.

You need to create a variable and name it yVelocity.

click the variables button below the numbers button and then click make a variable on the place where the blocks are.


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

 

#6 2007-10-27 23:36:20

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Re: Need a tutorial on gravity.

Ok I got them down thank you  smile  One last question how would I get an attack without making it go through the attack when I run...Like the sprites I make all go to the walking/running cycle how would I get it to press a single button then it would only do it for that button if you can under stand that...Not sure how to explain it any better...

Offline

 

#7 2007-10-28 00:38:49

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

Re: Need a tutorial on gravity.

Umm are you saying that you want an sprite to go through a certain animation when a certain button is pressed?


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

 

#8 2007-10-28 01:05:11

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Re: Need a tutorial on gravity.

Yes. When I push a certain button I want it do do a certain action so far when I make a new costum all it does is add it to the walk animation is there a way to create a new sprite and not have it added to the walk cycle/walk animation?

Offline

 

#9 2007-10-28 14:41:10

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Re: Need a tutorial on gravity.

I found a easyer way to explain...Is there any way I could "Link" Two costumes?

Offline

 

#10 2007-10-28 14:53:05

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

Re: Need a tutorial on gravity.

Just keep switching coustumes based on what the sprite is doing.

if you sprites is running then forever

switch to run1, switch to run 2, switch to run 3 and so on

if the sprite is jumping then
switch to jumping

and so on.


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 2007-10-28 15:02:27

Boboftibia
Scratcher
Registered: 2007-10-27
Posts: 6

Re: Need a tutorial on gravity.

Bit hard to follow but I think I know what you ment.

Offline

 

#12 2008-02-10 19:06:07

Icarlyrocks
Scratcher
Registered: 2007-11-10
Posts: 19

Re: Need a tutorial on gravity.

This tutorial should attract people!  big_smile   big_smile

Offline

 

#13 2008-02-10 19:23:26

Mike16112
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: Need a tutorial on gravity.

I found a lot on here(I could use help on my ssbm project  big_smile   big_smile   big_smile   big_smile   big_smile   big_smile   big_smile   big_smile  )


The programmer has a nap. HOLD OUT! PROGRAMMER!

Offline

 

#14 2008-02-10 19:47:20

Mike16112
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: Need a tutorial on gravity.

The code for the main sprite's gravity is  in my ssbm project is

<when green flag clicked>
<forever>
<set y to( sprite x )>
<end>

<when green flag clicked>
<forever>
<if> <key[  space  ]pressed?>
<repeat( 20 )>
<change{ sprite x  }by(0.3)>
<end>
<repeat until><<  <not><touching color[blue] >>
<change{ sprite x   }by(0.1)>
<end>
<end>


The programmer has a nap. HOLD OUT! PROGRAMMER!

Offline

 

#15 2008-02-11 02:26:36

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Need a tutorial on gravity.

What you need, I think, is for your walkcycle to only cycle through a set number of costumes, so that the other costumes can be used for other thinks.

Its fairly straightforward.  Say you have the 1st 6 costumes for walking.

Instead of just "nextcostume" you need

If costume = 5
> change to costume 1
Else
>Next costume.

Then costumes 7+ can be for different things.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#16 2008-02-11 09:25:25

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Need a tutorial on gravity.

You can also use the "mod" function to cycle through a range of costumes in one command.

Let's say  you wanted to cycle through 5 costumes, numbered 4,5,6,7,8.

You could do this with
    change to costume  4+ ( (costume+1) mod 5)

Offline

 

#17 2008-03-31 18:06:11

nikkiperson2
Scratcher
Registered: 2007-12-08
Posts: 1000+

Re: Need a tutorial on gravity.

i did this but i get stuck in the black before i can jump. it's like i go down to deep, or if im touching the ground i cant move.


http://i.imgur.com/h9L7Ktb.pnghttp://i.imgur.com/Hz1Cg2s.png

Offline

 

#18 2008-06-05 19:18:32

kslich1
Scratcher
Registered: 2008-06-05
Posts: 1

Re: Need a tutorial on gravity.

I read the script. Thanks. I just have one question. Say i want to have barrieors so that i can stand on them and not go through them. Do you know how i can do that?

It is basicly a platform that you can stand on.

Thx

Offline

 

#19 2008-06-05 19:21:07

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Need a tutorial on gravity.

Use If touching color whatever, change y by one


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#20 2008-06-05 19:21:35

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

Re: Need a tutorial on gravity.

kslich1 wrote:

I read the script. Thanks. I just have one question. Say i want to have barrieors so that i can stand on them and not go through them. Do you know how i can do that?

It is basicly a platform that you can stand on.

Thx

I think this project may have the codes you are looking for.
http://scratch.mit.edu/projects/archmage/101212


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

 

#21 2009-05-01 21:17:31

Oneandonly
Scratcher
Registered: 2009-02-07
Posts: 100+

Re: Need a tutorial on gravity.

Try this project I just made, it tell you what to do:

http://scratch.mit.edu/projects/Oneandonly/510350



This is just basic gravity. If you want more advanced, read the description for my project with ohysics and stuff...  cool     big_smile

Offline

 

#22 2009-12-28 11:43:11

gghdjjd
Scratcher
Registered: 2009-12-28
Posts: 2

Re: Need a tutorial on gravity.

archmage wrote:

To switch sprites while your enemy is walking just use the change costumes block.

I had posted a simple gravity tutorial in another tread but I guess I'll repost it with ways to make it react the the ground.


Ok people I will tell you how to implement gravity!

The way I implement gravity is very simple and logical and you probally won't think gravity is such a big deal anymore.

// First create a "this sprite only" variable on your sprite called yVelocity

Then put this script into your sprite.
// yVelocity will only change if player is not touching the ground
<when green flag clicked>
<set{  yVelocity}to(0
<forever>
<if>
<touching[ ground ]
<set{ yVelocity }to( 0
<end>
<else>
<change{ yVelocity }by(-1
<change y by( yVelocity
<end>

//Now that wasn't so hard was it?


Now to jump we invert gravity.
//The player should only jump if he is touching the ground
<when[ up ]key pressed>
<if>
<touching[ ground ]
<set{  yVelocity}to( 10
<end>


Controlling x and y velocity is an important of game design and it's good to learn about it  smile

The player should not fall though the ground but he might get stuck in it a little. To fix this the best way is to use color sensing. So if the color of the upper part of the sprites is touching the color in the ground make the sprite rise.

My Sprite Doesn't Jump! the velocity just goes up. what do i do?

Offline

 

#23 2009-12-28 12:49:34

ma88hew
Scratcher
Registered: 2009-09-08
Posts: 5

Re: Need a tutorial on gravity.

@gghdjjd: You need a script of

[blocks]
<forever>
<change y by( <{ Y_Velocity }>
<end>


http://img46.imageshack.us/img46/4350/anvalanche.jpghttp://img704.imageshack.us/img704/7572/cavezoomer.jpg

Offline

 

Board footer