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

#1 2008-01-28 14:32:40

SonicPops
Scratcher
Registered: 2007-06-10
Posts: 100+

I've learnt how to do side-scrolling - how do I make a character jump?

I know, it's a silly question - but I always have to copy a project's jumping sprite and use it in my game. How do I make a simple sprite jump and fall back down on black colored terrain?

If you could tell me I'd really appreciate it  smile


smile  Go Crank. Inc!  smile
Not much to say  wink

Offline

 

#2 2008-01-28 14:57:32

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

Re: I've learnt how to do side-scrolling - how do I make a character jump?

Ok first you need a variable called yVelocity. Now, put int the following code.

<when green flag clicked>
<set{ yVelocity  }to( 0
<forever>
<if> <touching[ ground or ground colour
<set{ yVelocity }to( 1
<if> <key[ up Arrow  ]pressed?>
<set{ yVelocity }to( 15
<end>
<end>
<change{ yVelocity }by( -1
<change y by(  <{  yVelocity }>
<end>

Last edited by archmage (2008-01-28 14:58:05)


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

 

#3 2008-01-28 15:05:27

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

Re: I've learnt how to do side-scrolling - how do I make a character jump?

It depends  wink

Simple way:
When you press the jump key,
glide to position (x) + 20, (y) + 20
glide to position (x) +20, (y) -20

So your sprite will jump diagonally up and forwards, 20 pixels and fall diagonally back down.

Of course, if your background is moving, you don't need to add anything to (x).

***

You can get much more complicated if you start having gravity, and you will probably want to do that if your project requires jumping on platforms rather than just jumping over obstacles.

For that, you will need a gravity script that causes your sprite to fall when not standing on a platform, and a jumping script that causes the sprite to move upwards and ignore the gravity until it reaches the top of its arc.

See Gobo and The Flood, or my "Complex Jumping Demo"

***

Or you can start getting into realistic jumping where you have vertical velocity that gets modified by gravity... but one step at a time, hmm?


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

 

#4 2008-01-28 15:12:15

SonicPops
Scratcher
Registered: 2007-06-10
Posts: 100+

Re: I've learnt how to do side-scrolling - how do I make a character jump?

Thanks you 2  big_smile

This'll help  wink


smile  Go Crank. Inc!  smile
Not much to say  wink

Offline

 

#5 2008-01-28 17:26:17

rockie
Scratcher
Registered: 2007-11-18
Posts: 100+

Re: I've learnt how to do side-scrolling - how do I make a character jump?

there are many projects that show you how to jump with gravity. look at those and they will help.


No signature currently stored in profile.

Offline

 

Board footer