Jump to content
  • Advertisement
Sign in to follow this  

Help with simple physics update!!

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

I'm working on a platform game with some people in a class, and I'm having a problem with my physics class update. First of all, here is the physics code:
acceleration = force + gravity + (velocity * dragCoefficient);	
velocity = velocity + acceleration * dt;
position = position + velocity * dt;
force = force * frictionCoefficient;
dt is deltaTime and is in seconds. obviously it's a very very small number. acceleration, force, gravity, velocity, and position are all vectors (2D vectors with only an X and Y). I know that "frictionCoefficient" isn't the correct term for this, but i needed a way to slow the player down, and change their friction on icy terrain. I have some frictions #defined, such as #define FRICTION_AIR 0.998 and #define FRICTION_GRASS 0.6 Right now i have gravity set to Vector2D(0.0f, 100.0f). Yes, I know that 9.81 is proper. The real problem I'm having is that jump won't always work. And in order to get it to work I have to set force to -4000 in the Y. otherwise i just stay stuck. SO....yes...I know this is a bit scattered. If you need ANY info i'm not giving then let me know please. Basically I know there is something wrong with my physics update but i'm not sure what it is. I need to apply an initial force that makes more sense to make the character jump. -4000 is a bit much. in order to walk i'm currently doing force.x += 25 (for right...-= 25 for left) Please help..and thanks in advance!

Share this post

Link to post
Share on other sites
It seems like you wouldn't want to change the force every time through.
For jumping, you want to model a projectile - but a projectile only has an initial force...after that, the only force acting on the object is gravity and wind resistance.
For walking, the person would always be exerting the same force, trying to move. Friction would act against that force, and the velocity should be calculated from that (although the velocity should be maximized).

Remember from physics class:
velocity = delta(position) / delta(time)
acceleration = delta(velocity) / delta(time)
force = mass * acceleration

Hope something here helps...

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!