Can you me understand drag and gravity?

  • Thread starter Thread starter cubby208
  • Start date Start date
  • Tags Tags
    Drag Gravity
Click For Summary
SUMMARY

This discussion focuses on implementing realistic drag and gravity in a basic 3D platformer. The key points include using a gravity constant of 9.81 m/s² for vertical velocity changes and understanding that drag is proportional to the square of the velocity. When a player collides with walls or ceilings, they should decelerate over a distance rather than stopping instantly. Additionally, the discussion emphasizes the importance of modeling mass and inertia to achieve realistic movement dynamics.

PREREQUISITES
  • Understanding of basic physics concepts such as gravity and drag
  • Familiarity with 3D game development principles
  • Knowledge of velocity and acceleration in a programming context
  • Experience with game physics engines or libraries
NEXT STEPS
  • Research how to implement drag in Unity using Rigidbody components
  • Learn about terminal velocity and its effects on falling objects in game physics
  • Explore physics engines like Box2D or Bullet Physics for realistic movement modeling
  • Study collision detection and response techniques in 3D environments
USEFUL FOR

Game developers, physics programmers, and anyone interested in creating realistic movement mechanics in 3D platformers.

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?
 
Technology 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?
 
Game developers usually use 3rd party code in these situations. I'm sure you can find a free physics engine to use.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
630
  • · Replies 3 ·
Replies
3
Views
760
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 3 ·
Replies
3
Views
8K
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K