Sign in to follow this  
Darobat

Jumping

Recommended Posts

Darobat    100
Greetings. What would the best way be to implement jumping? I have a class, Entity, that contains a player. Should I add a variable like bool jumping, then another one that keeps track of there the user is on the y-axis or is there some better way to make the player jump? Thanks.

Share this post


Link to post
Share on other sites
hplus0603    11356
That depends on what kind of game you're making.

For "ballistic" jumps, you typically just keep a "current velocity" and when jumping, you give a pretty hefty kick (impulse) upwards. This will make the current velocity go upwards. Each step, gravity will start pulling the velocity down, until you start to fall, and eventually hit the ground again; then collision will negate the velocity and you're running straight.

For more "stateful" jumps, you probably need to add logic state to your character controller; typically you will add an enum for the controller state ("standing" "running" "jumping" "crawling" etc), and a counter for how many steps since the state started; then the update logic will look at the state and the counter, and figure out what the right action is. (OO fanatics will factor this enum into a polymorphic class.)

Share this post


Link to post
Share on other sites
Boku San    428
Someone should make a completely realistic jumping simulation. Like, given weight-to-muscle ratio, with all kinda other fancy high-techy buzzwordy things thrown in, they should simulate an actual jump.

It really would be cool to simulate me jumping off a building to see whether or not it would hurt. Because throwing your best friend off first isn't *always* an option.

Share this post


Link to post
Share on other sites
_Phalanx_    180
well determining whether jumping off a building would hurt is a lot different than creating a jumping simulator, but i assume you were joking. :)

uhh you need to think about all sorts of different things, you really havent given us much information about your game. the most simple way would be to add char or something that defines the current animation of your person, and make one coorespond to the jumping animation. And when you need to accomplish whatever you were trying to do by jumping, you could just have a if(PlayerState & jumping) to see if the person is jumping.

If you have physics acting on your game objects, then this is very easy, just simply add to the players upward velocity and gravity will pull you back down. This is a much more robust solution becuase the positon of the player is different allowing for dodging bullets and jumping over stuff :), but then again you have to write a physics engine :(

Share this post


Link to post
Share on other sites
Structural    328
Quote:
Original post by Boku San
Because throwing your best friend off first isn't *always* an option.

Depending on the building ofcourse, this is only an option the first time ;)

But what hplus0603 said sounds a good solution. Give the character some upward velocity. For animation purposes and to check if the character is already airborne you would need a flag to indicate the character is jumping.

Share this post


Link to post
Share on other sites
Boku San    428
_Phalanx_'s post sums up about the whole what's-been-said in the thread, pretty much.

And actually I wasn't kidding about that building thing, jumped off a building yesterday. 'Cept that building was a shed.

It's uh...what we do. Jump off/over stuff.

Share this post


Link to post
Share on other sites
Lode    1003
Give your class an x and y coordinate (floating point).

Then do the following:

~Every Frame~
t = TimeSincePreviousFrame;
if(y > theGround) y += t * someVelocity;

So that the speed of falling is independent of the FPS.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this