# Jumping in a 2D fighter

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm working on a 2D fighter and I'm having trouble figuring out how to have a nice smooth jump and a smooth fall, as well as stopping the player from accelerating in his Y position while the jump button is being held down. I was thinking about doing a check to see if he is on the floor and if he is then he can be accelerated into the air and then droped down during the course of time. However, I'm not really good with programming physics into a game, I'm more of an AI programer. Anyway, I was wondering if anyone can please help me.

##### Share on other sites
You should be able to do this with some very simple physics. First you'll need a y velocity variable for your player. Every frame you'll need to do a couple of things.

1. Accelerate your player in the y direction to simulate gravity. The value of g will depend on your units, but the idea is:

player.yVelocity += g * dt;

Where dt is the time step for that frame.

player.y += yVelocity * dt;

3. Resolve collisions. Collision detection is another issue, but we'll take a very simple example where player.y is the bottom of the player and 'ground' is, well, the ground:
if (player.y < ground)    player.y = ground;
3. You only want to allow jumping (I assume) when the player is already on the ground. So, you could structure your code like this:
if (player.y < ground){    player.y = ground;    if (jumpButtonIsPressed)        player.yVelocity = initialJumpVelocity;}
I may have skipped over something, but that's the basic idea. Does that answer your question at all?

##### Share on other sites
Thank you so much. I think I should be able to implement this. I do realize it required simple physics, but well... I'm not good at physics. Anyway I will implement this as soon as possible in the game and should I have any trouble I'll post again. Thank you once again.

##### Share on other sites
Castlevania kicks ass.

1. 1
Rutin
70
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633422
• Total Posts
3011804
• ### Who's Online (See full list)

There are no registered users currently online

×