Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can you please help me understand drag and gravity?

  1. May 21, 2015 #1
    So, I was working on some code to handle this.

    Basically the setup is I have x, y, and z velocity. So if x is negative then move left. If y is positive move up. Z is positive move forward etc.

    When keys are pressed I add (or subtract) to the proper velocity value. Their are two parts of this code I just cant wrap my head around. One is that when the player is on the ground I want movement to feel like it is not a velocity based platformer. Feeling close to walking, however as soon as the player jumps I want it to be different. I want the jump to have direction to it based on the players velocity. In short emulating reality fairly closely. Second is gravity. I dont understand it! Ill summarize below what I don't get.

    It is a basic 3d platformer, and only one object will be moving so no need to worry about mass. Also their are no slopes.

    Anyway here are my main questions.

    1. How should I process drag both on the ground and in the air to simulate reality?

    2. How do I apply gravity? About what number should I use? Do I need to account for "terminal velocity? If I am falling do I constantly subtract gravity from the y velocity?

    3. When the player runs into a wall (not floor or ceiling) what should happen to the velocity? No need to account for restitution, and probably not friction.

    4. What should happen to the velocity when the player hits a ceiling?
  2. jcsd
  3. May 22, 2015 #2


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    What do you mean by "drag"? Friction? Air resistance? Both are essentially forces that act in the opposite direction to motion. You could assume friction is a constant force. However drag is typically proportional to velocity squared. You would need to model the concept of mass and inertia as well. For example two objects might be the same size and have the same air resistance - but if one is heavier it will take longer to stop when subject to friction.

    Gravity is an acceleration. So yes in free fall the vertical velocity changes by 9.81 m/s/s. If you model drag correctly you get "terminal velocity" for free.
    When someone hits a wall they don't stop instantly. Their body deforms which provides a stopping distance. They decelerate from some velocity to zero over that distance. Clearly their head can't deform as much as their body so it depends which part contacts the wall. Different parts will experience different rates of deceleration. All very hard to model I imagine.

    Same as a wall or floor.

    I'm no programmer but I understand some games development software includes physical modelling tools to help with this?
  4. May 22, 2015 #3


    User Avatar
    Gold Member

    Game developers usually use 3rd party code in these situations. I'm sure you can find a free physics engine to use.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook