# Vehicle in newtonian physics?

This topic is 3271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, in my small RTS project I finally decided to integrate some sort of physics. But now, I don't know how to make vehicles move in terms of forces and torque. And how do you implement friction? At the moment everything acts like boncy balls in space since there isn't any friction. All my objects are supposed to be on the ground, so they should have lots of friction against it. Friction against the ground or something similar should be constant, so basically a constant force acting in the revers direction of the motion. But if i implement that like: velocity -= F_friction/mass. the objects won't stop, instead they will oscillate (I am aware of the reason for it, but I don't know how to fix it). Also I'm completly lost how to describe vehicle movement in terms of forces and torque. I don't want my vehicles to drift around like they would if they just always accelerate into the direction they are facing at the moment (like the spaceship in asteroids).

##### Share on other sites
Have you tried simply v = v * X, where X is some constant less than 1, e.g., 0.98?

This is not a strictly correct model for friction, but I've found it functions as a good approximation.

##### Share on other sites
just an aside question, have you considered using an existing physics engine to do all of this stuff for you? Bullet would be the obvious, free choice?

##### Share on other sites
You're trying to model what's actually a mildly complicated subject. In fact, there are two types of friction involved in "slowing" something down - static friction and kinetic friction.

Kinetic friction is (supposedly) independent of velocity and, as you have it modeled, is proportional to the coefficient of kinetic friction times the normal force (or the mass if it's on a level surface). At some point, as the velocity decreases, static friction "takes over" and the object is simply stopped.

Unlike kinetic friction, static friction is always in the opposite direction of an applied force. If there's no force applied (as when your object stops and isn't being pushed), static friction is zero.

Having said all that, justkevin has the right idea but has the opposing force proportional to velocity. Simply apply a constant deceleration (like you have already) until the velocity is zero. With no applied forces, the friction forces are then = 0. For simulation purposes, apply the deceleration and test if the velocity is zero or has changed direction. If it has, just set it equal to zero.

Without getting into coefficients of static and kinetic friction, Coloumb forces, etc., that simple method is close enough to reality.

If you want to model it more closely, remember that friction/mass is an acceleration, not a velocity. velocity = velocity0 + acceleration*time. Your equation velocity -= friction/mass assumes a fixed time period (one second) which is okay if that serves your purpose. If you want to make it time-based, which an RTS implies, acceleration = friction/mass * deltaSecs, and velocity -= acceleration. "deltaSecs" in this case is your update rate, whatever it may be ( e.g., 0.0167 secs for 60 frames/sec).

EDIT: if you're simulating the physics just as an excercise, that's understandable. If not, as silvermace suggests, you might want to consider one of the several collision detection/physics libraries that are available. Bullet, Havok, ODE all have similar capabilities. I happen to use ODE for my vehicles and have incorporated the capability for settings of shocks, springs, various tire and surface frictions, variable ratio steering, front-wheel vs. rear-wheel drive, gearboxes, engine horsepower, etc., and let the physics engine take care of the rest.

[Edited by - Buckeye on December 25, 2009 10:18:34 PM]

##### Share on other sites
Ok, thanks to everyone for the suggestions. I fixed the friction issue with Buckeyes approach to simply set the velocity to zero if the only force acting on the body is friction and the velocity changes direction.

I am doing this project for "educational purposes" so implementing the physics myself makes sense to me.

Now the vehicle physics is still to be done. I guess i have to explicitly add a centripetal force when the vehicle is turning to make it drive realistically. That should be:

F_centripetal = (new velocity - old velocity)*mass/dt

where "new velocity" is the desired direction of movement (speed*(sin(orientation),cos(orientation)))

right?

##### Share on other sites
Rather than messing around with "centripetal force," which is really just a result of applying the ol' f=ma equation, you may just want to stick with f=ma directly. In the "real" world, the vehicle would be influenced by forces from the tires. The forces on the tires would be a result of kinetic friction opposite to the direction of each tire's velocity.

For the tires aligned with the direction of the chassis and driving (e.g., rear driving wheels), the force due to friction at the bottom of the tires is opposite to the direction of the chassis and f=ma should serve, driving the chassis forward. The velocity of steering wheels is aligned with the chassis direction (since they're just rolling) but, if they are turned, friction forces "push" them to the side in the direction of the current steering direction.

That is, if the wheels are moving forward but turned slightly to the left, friction forces opposite the velocity are applied slightly to the left, applying a force and torque to the chassis through the suspension. The force (applied to the CG - center-of-gravity) moves the chassis to the left, and the torque (about the CG) rotates the chassis slightly to the left. If the wheels aren't straightened, the vehicle continually moves to the left and rotates to the left, going in a circle.

You can calculate the friction forces on the tires and convert those to forces through the CG and torques about the CG on an axis = cross-product of force and velocity (left-handed, or vel*force right-handed). Torque = force * distance-from-center-of-gravity.

For the driving wheels, each wheel applies a forward force to the CG and a torque. Because the wheels are on either side of the CG direction, the torques cancel out (unless one wheel slips).

For the steering wheels, each applies a force normal to the velocity through the CG, and a torque proportional to the friction times the distance from the CG to each tire. Both of those torques are in the same direction and don't cancel out.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013168
×