forums

TNT Basic Forums > Programming Q&A
Algorithym for jumping...
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-09-2003 07:15

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

I'm making a side scrolling engine but I can't figure out jumping.

Sure, I could make it so when I hit the jump key it makes the character fly upwards for a set amount of pixels then reverse and come back down (Which I basically almost have now.) but I'd like it to be like real jumping like Mario does or Sonic or just about any character in any platformer ever made.

What I mean is how when they get close to the peak of their jump, they start slowing down then halt for a millisecond then reverse and start to pick up speed.

What kind of mathematical calculations would I use to do this? Some basics.

I'd like to make it like Mario where if you hold the key he jumps higher and if you tap it he just jumps a little. I just need to figure out the slowing down and speeding up parts.

08-09-2003 09:02

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Just use a velocity variable. Every frame, decrease upward velocity by a little to simulate gravity. Then move the sprite up as many pixels as the velocity. This will simulate gravity. So when you press the jump button, you set the upward velocity to a certain number and it will go up and fall down.

Someone else can probably give you a better explanation or method though.

08-09-2003 09:10

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

I think code can explain better too, so here:

quote:
graphics mode 800,600
int upVelocity=0,jumping=false
int gravity=1
int x=100,y=100
repeat
upVelocity=upVelocity-gravity
if up and jumping=false
upVelocity=10
jumping=true
end if
y=y-upVelocity
if y>=100
y=100
jumping=false
end if
set pen color black
paint canvas
set pen color blue
fill rect x,y to x+10,y+10
draw frame
until mouse button

08-11-2003 06:40

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

Hmm.. I was expecting something with Sin's and Cos's. But I'll try this.

Thanks.

08-11-2003 14:47

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I don't know if Sin and Cos can be used for jumping, but I only use them for rotation.

08-13-2003 06:21

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

Well, when I was playing with the Sin and Cos in my other thread. I noticed that if you look at how the point moves when doing an arc, it goes up, gradually getting slower, then peaks and stops, then starts coming down slow then speeds up. Like you would when jumping, so I thought that would be the answer.

09-24-2003 00:38

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

you should use tangent for jumping :>)

09-24-2003 05:59

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

To simulate gravity (which is what you're really asking for) is simple.

Give gravity a value of say 1. Lets say the character jumps so he's gaining altitude at 10 pixels per frame. After each frame, subtract gravity from it. Eventually, he will start moving downward. Like so:

Frame|Height
-----------
0 0
1 9
2 16
3 21
4 24
5 25
6 24
7 21
8 16
9 9
10 0

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.