Can you me understand drag and gravity?

  • Thread starter Thread starter cubby208
  • Start date Start date
  • Tags Tags
    Drag Gravity
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 1K views
cubby208
Messages
6
Reaction score
0
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 can't 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 don't 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?
 
Physics news on Phys.org
cubby208 said:
How should I process drag both on the ground and in the air to simulate reality?

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.

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?

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 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.

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.

What should happen to the velocity when the player hits a ceiling?

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?