Jump to content
  • Advertisement
Sign in to follow this  
Richter

Jumping in a 2D fighter

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

2. Update your player's position:

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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!