Can you me understand drag and gravity?

In summary, the conversation discusses the challenges of creating a realistic physics system for a 3D platformer game. The main questions revolve around simulating drag, applying gravity, and handling collisions with walls and ceilings. The concept of drag is explained as being proportional to velocity squared and dependent on mass and inertia. Gravity is described as an accelerating force that can lead to terminal velocity. When colliding with a wall or ceiling, the player's velocity should decrease over a certain distance. The use of 3rd party physics engines is suggested as a solution for these challenges.
  • #1
cubby208
6
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
  • #2
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?
 
  • #3
Game developers usually use 3rd party code in these situations. I'm sure you can find a free physics engine to use.
 

Related to Can you me understand drag and gravity?

1. What is drag?

Drag is a force that acts in the opposite direction of an object's motion, slowing it down as it moves through a fluid (such as air or water).

2. How does drag affect an object?

Drag affects an object by reducing its speed and causing it to experience resistance as it moves through a fluid. This can make it more difficult for the object to accelerate and maintain a constant speed.

3. What is gravity?

Gravity is a force that pulls objects towards each other. It is responsible for keeping objects in orbit around larger objects, such as the Earth around the Sun, and for keeping us grounded on the Earth's surface.

4. How does gravity affect an object?

Gravity affects an object by pulling it towards the Earth's center. The strength of the gravitational force depends on the mass of the objects and the distance between them. This force can cause objects to fall towards the Earth's surface and also keeps planets in their orbits around the Sun.

5. How do drag and gravity work together?

Drag and gravity work together to influence the motion of an object. Gravity pulls the object towards the Earth, while drag acts in the opposite direction, slowing the object down. As an object falls, gravity pulls it towards the Earth and drag opposes this motion, eventually reaching a point of equilibrium where the object falls at a constant speed (known as terminal velocity).

Similar threads

Replies
6
Views
843
Replies
3
Views
5K
Replies
13
Views
2K
Replies
2
Views
1K
Replies
10
Views
1K
  • Classical Physics
Replies
2
Views
207
  • Introductory Physics Homework Help
Replies
18
Views
4K
  • Introductory Physics Homework Help
2
Replies
41
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
Back
Top