character jump [Archive] - C Board

PDA

View Full Version : character jump


pode
12-29-2002, 10:05 PM
hi all!

know a good way to jump the character
when a key is hit. i'm trying to make a
super-mario clone.
i'm making this in allegro.

Polymorphic OOP
12-30-2002, 07:14 AM
I've never used allegro, personally, but here's how you'd do it with just about any API -- Use vectors for velocity and acceleration, come up with some constant for gravity (9.8 m/sec is about earth's gravity), then when the player jumps add an arbitrary amount to his velocity vector in his jump direction (usually straight up), then everytime you update your scene, subtract from the y value of the velocity vector (assuming gravity is straight down) the amount of time passed times the gravity constant you created.

pode
12-30-2002, 08:10 PM
how would i make the character first go
up then back down?

frenchfry164
12-30-2002, 09:07 PM
Actually, gravity is 9.8 meters a second per second.

You don't need vectors. The simplist way would be just to have a velocity variable, you could use int float or double to store this. Have a constant value defined on how much gravity effects this variable, and initial velocity. When the player presses the jump button, make the velocity variable equal the initial velocity. Everytime you update the player's movement add the velocity variable to the y value of the player. Make sure initial value is a positive number. Then subtract the gravity from the velocity over and over.

To sum it up: have a variable hold velocity, change character's y value according to the variable, then subtract gravity from velocity.

Polymorphic OOP
12-30-2002, 10:05 PM
Vectors make it easier -- you don't always have motion in a single direction -- jumping while moving for instance isn't a direct upward jump -- with vectors you can just add to the y component of the vector to get the new vector.

pode
12-30-2002, 10:41 PM
THAT WAS EASY as %&¤%/(/)#¤"

you just need to -- its value while the
character isnt touching ground
then just ++ it when hit key!

simple as that!!!?
i cant believe it i didnt figure this out in the first place.
anyway guys thanks alot for your replies
so now i need velocity, btw can u explain how velocity works??:confused: i got no idea
thanks again.

frenchfry164
12-30-2002, 10:46 PM
dude, it doesn't restrict your x movement. You can still change your character's x value.

Polymorphic OOP
12-31-2002, 07:22 AM
Actually, gravity is 9.8 meters a second per second.

Yeah, thanks for the correction. I actually was gonna look up the ascii character for a ² to put after the sec when I finished the post, but I forgot to by the time I finished.

dude, it doesn't restrict your x movement. You can still change your character's x value.

Well then you do have an x velocity and a y velocity -- you're just not storing it in one data structure. Velocity with x and y direction makes a vector, that's why most people store it as one.

so now i need velocity, btw can u explain how velocity works?? i got no idea
thanks again.

Velocity is your rate of movement -- similar to speed but can have direction.