Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

Platformer programming theory

This topic is 3542 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

probably soon I will be handed the task of creating a platformer game, and I was thinking a quick way of handling the collissions of such game I havent yet searched on google about this, but I will as soon as I finish writing this, I apologize if this has answered already but I really like using the forums and reading what people have to say. so here are a couple of questions: is there a better way to handle vertical collisions than applying a gravity modifier to every actor in each frame? what is the correct way of handling jumps, should I apply mathematical functions to determine the actual jump arc? or hardcoding values is just as good? does anyone knows how jumps where handled in super mario bros (nes versions)? Thanks for reading

Share this post


Link to post
Share on other sites
Advertisement
Generally, game physics defy real world physics. Consider the fact that in most games you are able to alter your direction of motion while being in mid-air! The easiest way I've found is to apply a downwards force and nothing else (maybe a movement restrictor like a 0.5 multiplier on horizontal movement speed). Then perform collision detection as normal.

Share this post


Link to post
Share on other sites
For a platformer, you can get good jump results using m0nkfish's suggestion of simply applying a constant velocity modifier to bring the character back down to earth more naturally (in that they will decelerate to a stop going upwards and the accelerate back down to the ground).

To get the player off the ground in the first place simply apply a instantaneous velocity upwards to the player.

When you look at a game like Mario though there are several other components to a jump though. One has to do with tapping versus holding the jump button. The way you can simulate this is to continuously force the player's upwards velocity to the instantaneous jump velocity as long as the button is held (up to a certain height).

Another thing to consider in mario is the horizontal movement while in the air. You'll probably want to know the horizontal velocity at time of jump and come up with different rules for affecting the player's horizontal movement while in midair. This isn't really a physics issue though as people really can't adjust their movement while in air (outside of factors outside of our control such as wind that is).

Share this post


Link to post
Share on other sites
I use a vector of forces with the first being gravity in the down direction. the rest of the vector could be wind forces or other forces based in your game world. Just remember the game shouldn't be real world physics but instead modeled after them.

I usually have a state based character for things like jumping.. standing.. sliding.. running.. Each of these states could have different types of physics applied. IE: if your standing and hit jump you just apply a upward velocity to your character once and while your not colliding with the 'ground' you apply gravity.

Share this post


Link to post
Share on other sites
I see, and what about handling collisions to avoid characters falling through platforms?

my current idea is to be always incrementing its y value (like a gravity force)
and then check for collisions for the underlying area of each entity, but this sounds a little costly isnt?

Share this post


Link to post
Share on other sites
directx comes with a math library that has something like check RECT collision that will return if two rectangles collides.

you could do 2d vector math after finding the collision.

project the closest point onto the rectangle and get the penetration depth. then negate it and add to current position, this will put you exactly at the point you collided with it.

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!