Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Sep 2012
Offline Last Active Nov 21 2012 07:41 AM

Topics I've Started

[Car Physics] Sharing work, ideas, formulas and car parameters

26 September 2012 - 08:01 PM

Hi again to everyone

I noticed we are now at least 3 on this forum, trying to create a proper car simulation. It seems everyones main goal is to create something fun (drifts...), based on realistic physics, but not too hard for the player. So closer to something like GRID than Forza.

I think i am right when i say this : we all want the kind of fun we can find in games like NFS. If a game like NFS or GRID (or even the Steam racing casual games) can only be achieved by using some cheats or specific player input tweaking, i suppose we all want to know what they are.

What i propose here is :
  • Share the fundamental basics every car simulation based on newton physics should have. eg : weight transfer, pacejka-like curves for getting output of SR/SA....
  • Share one or two basics car models and parameters to be sure we are talking about the same thing.
  • Share some reference values/behaviours in predetermined situations, so that everyone can compare their own values with some reference to know if things are going right or wrong.
  • Share math/physics formula, tips & tricks, or cheats & shortcuts that would allow us to make the game more fun. Because we must not forget, it is all about fun in the end.
I would try to maintain the first post as updated as possible as people bring their contributions. So if this thing is going well, it could be a very good starting point in the future for programmers wanting to create their own car simulation.

I'll start to fill the blanks, and i hope the car experts will bring their knowledge to be sure future readers won't be misleaded by the things listed here.

One of the goals here is to cover 2D and 3D games, as the car behaviour will be similar in both situations.

Part 1 - What should i absolutly do to make this a fun game with drifts, skids and such things ?

Let's make an exhaustive list of things needed to achieve a drifting behaviour on a racing car.
  • Get basic newton physics right : forces, acceleration, torque, integration. You can use a physics engine for this, like box2d or PhysX.
  • At first use a 1ms timestep to update the simulation at a decent rate and avoid bad approximations.
  • Create 4 wheels and attach them to the body.
  • Use wheel distance to CG to calculate weight transfer lateraly and longitudinal. Combine those two.
  • Use real car suspension/springs/anti roll bars, or the weight transfer will just be instantaneous and make the car highly unstable.
    Subsidiary question : is it vital to have proper car suspensions ?
  • Use some "soft" player inputs, and try to limit steer angle at high speed to get good lateral forces, or the car might be totally uncontrolable. Or use realistic driving accessories.
  • Find out velocity for each wheel contact patch, transformed in the wheel space. So if the wheel is heading 45° and the car going straight, the front wheels will have both X/Y velocities, as rear wheels will only have Y (if Y is front).
  • Use the powered wheels velocity to determine motor RPMs. Based on player throttle input, and engine torque curve, generate a torque force for powered wheels.
  • Apply torque on wheel so it increase their angular velocity.
  • Calculate wheel slip angles and slip ratios.
  • Use a plotted pacejka curve, or a real formula to find out the normalized force the tire must produce front/lat.
    Subsidiary question : is it vital to have the original formula instead of a simple pre-plotted curve ?
    Subsidiary question : is it vital for nice drifting to have combined lateral/front formula ?
    Subsidiary question : is it vital for nice drifting to feed directly the real load to the formula ? If i multiply the normalized 1N value by the wheel Fz result is supposed identical right ?
  • Create a vector for front/lat forces, and check this vector on friction circle/ellipse. Cut any part which is not inside the circle.
    Subsidiary question : should ellipse max values be the same as pacejka normalized max values ?
  • You can now multiply the remaining vector by the wheel weight (Fz)
  • For the longitudinal component of the force, reintegrate it in the wheel (with the radius), so it decrease their angular velocity. That part is what makes the wheel angular velocity adapt to the car speed.
  • Apply the resulting forces to the body, at the attach point of the wheel, or directly the contact patch in 3D, and calculate resulting torque/acceleration on the body.
  • When 4 wheels have generated torque/forces for the car body, integrate those values in the physical engine to produce velocity and move the car.
  • Apply damping forces (rolling friction, air drag). It is not supposed to be vital to car behaviour, but it might help a little. It will mostly influence acceleration time and maximum speed.

That should be all what is needed to get a car simulation right. At least theorically. I think i have forgotten nothing.

Part 2 - The reference car(s)

The goal of this part is to have reference values for a classic car, so we can compare our values and behaviours.

The classic car inspired from some Corvette C5 values and other frequent values seen here and there. Let's call it X-Car-1

To be honest i must say this reference values don't make a nice car. I'll post a general handling video soon.

Here are some parameters taken from Edys Car Vehicle Physics for the Red Pickup you can try in the demo. Some of the values can be monitored with B and the SHIFT+B in the demo. I post it here to give some elements to discuss about as a part of those values are not present above, and for some i just dont know what they mean. Any idea / insight would be appreciated.

Part 3 - Reference handling and values

The goal of this part is to put the car in a typical situation with controlled environment, and to look at what happens. Game may be written in Java, .NET, Unity or whatever, if you have taken control of the physics, and if you have the right car parameters, the values should look like these.

X-Car-1_T01 : apply 100% throttle for 10.00 seconds
Coming soon...

X-Car-1_T02 : launching directly the car with a front velocity of 50 meters/s
Coming soon...

X-Car-1_T03 : launching directly the car with a side velocity of 50 meters/s
Coming soon...

X-Car-1_T04 : launching directly the car with an angular velocity of 10 radians/s
Coming soon...

X-Car-1_T05 : launching directly the car with a combined front/lateral velocity : 50m/s in each direction
Coming soon...

X-Car-1_T06 : launching directly the car with a combined front/lateral velocity : 50m/s in each direction and a 10 radians/s angular velocity
Coming soon...

X-Car-1_T07 : apply 100% throttle for 10.00 seconds, then without releasing throttle, press the right key for the next 10.00 seconds (right + full throttle)
Coming soon...

X-Car-1_T08 : apply 100% throttle for 10.00 seconds, then release throttle, and press the right key for the next 10.00 seconds (right + free roll)
Coming soon...

X-Car-1_T09 : apply 100% throttle for 10.00 seconds, then apply brake, and press the right key for the next 10.00 seconds (right + brake)
Coming soon...

X-Car-1_T10 : a controled drift situation (still have to find a reference test)
Coming soon...

Part 4 - Tips & tricks

This part is still R&D, and i am more open to debate and wanting to collect ideas and tests than trying to explain to do this or not. I do not have the solution for doing most of those things anyway.

List of "legit" tricks :
  • Limit maximum steer angle according to speed & max grip peak SA
  • Same for throttle/brakes with peak slip ratio output
  • Decrease gently (or not) steer angle after input release
  • Be aware (you, programmer) of when a drift situation occurs and change car control inputs to help player have more fun
  • Instead of modelizing a complex combined front/lat grip formula, just determine how much percent of lateral grip you lose in function of the slip ratio

Cheap tricks or cheats :
  • If player apply throttle, just directly add front Y velocity to car
  • Disable real front/rear weight calculations. Just decide of a prefixed weight change on acceleration/braking situations
  • Gently decrease forces near/after traction circle max value, instead of just cutting it
  • Rotate directly car velocity vector by a very small percent of the front wheels slip angle
  • Use a linear slipAngleInRadians * someConstant formula for lateral pacejka output

Part 5 - Reference formulas and ressources

More content to come...

Reference physics formulas, tutorials and references...

Part 6 - Questions, FAQ, things we don't know

Questions :
  • What is the formula to have a friction ellipse instead of a circle ?
  • Where can we find a simple formula for combined long/lat grip ?
  • Should we apply a static friction force or something like that or just pacejka ?

  • Should i apply forces lateraly to car body or to the wheel ?
    To the wheel.
  • More classic question and answers to come...
  • What value can i use to decide if i must draw lateral drift skidmarks ?
  • What value can i use to decide if i must draw burnout skidmarks ?
I am a little bit tired, but i will update with more basics.

I'm looking forward to read your answers and contributions, if anyone interested !

Car Simulation Headaches Part_#2

09 September 2012 - 07:19 PM

Hi to everyone !

Another topic on car simulation, guys ! First i must say thank you to all previous car question posters and the great people who helped them (like Kunos, K_J_M, and many others...). You are my heroes since i started to work on my racing game a few month ago ! I have to say i have read and recoded every single tutorial available on the internet and studied a LOT of car physics game source codes, including the ones posted here.

So, i'm developing this top-down racing game with semi-realistic physics where the main aspects are : having fun, nice skidding turns, and car parts looting/upgrading. So i need a credible model, not too realistic. Something with engine, torque curves, slip ratios, slip angles, a little of pacejka and newton physics seems perfect !

Everything is quite OK to me except the turning part, which is always tricky. I spent the whole week on this topic : http://www.gamedev.n...ation-headache/ and it helped me as much as it confused me !

Before explaining my problem in details and start asking what i may be doing wrong, i think the best is to ask for some clarifications about a thing or two that still confuse me (like conventions, and so).

So, my first question will be about the tires longitudinal and lateral velocities used in the formulaes. It is the basing element everyone talks about and no one ever takes time to explain seriously.

Here are my assumptions about how to get those lat/long velocities :
  • Start with the car local velocity
  • Get world velocity of the car
  • Get the world coordinates of the wheel you want to calculate things for
  • Get the world velocity of this point (ie : the speed at wich the ground flies beneath that point)
    THAT MEANS : if the car is not moving, but is spinning on itself, there IS a velocity for each tire in X/Y. I am precising this because this assumption of KJM confuse me :

    If we assume your car is stationary and points at 12 o clock with the front wheels centred, but is spinning on it's axis (yaw) then the wheels generate 0 slip angle because there is no long or lat linear velocities of the car.

  • Convert the point velocity in car frame if necessary.
  • FInd unit vector in front/side of the wheel, and rotate them according to steer angle of the wheels.
  • The previous point velocity vector is projected on unit vectors to find front/side velocity.
  • As i can't use the Length() method of my vector (which returns unsigned result), let say i rotate back the projected vectors of -steerAngle, so i can have the length directly with the x/y values.
  • The X value of the projected vector on side is the lateral velocity (signed), same goes for the longit velocity with Y.
  • Positive X means the wheel is moving to the right.
  • Positive Y means the wheel is moving to the front.
  • In order to be a side friction, the slipAngle must always be of the opposite sign of the lateral velocity of the wheel (after all the perpendical friction of the wheel does nothing besides slowing an already existing velocity, which in returns generate a cornering force allowing us to turn the car). Am i right ?
A few examples to make sure i understand everything on this definition of frontal/lateral velocities :

(friction is not enabled in examples so the car keep applying any force i gave initially)
I will use the front right wheel as base for calculations of velocities in the examples.
The formula i use to calculate slip angle is :
-Math.atan2(wheelRealSideVelocity, Math.abs(wheelRealFrontVelocity));
I guess this formula is wrong. I could use this one from marcos tutorial, but i am totally confused with the omega things, because i think my method already takes angular velocity and steer angle in count before that step... Anyway this formula is different of mine or the one you can see in this topic. KJM and bmarci even ended using slightly different formulas.
Posted Image

Example 1 : a car is heading front at 4m/s. The front wheels are steering at Pi/6 (30°). You can see a picture of it here with the different measured values and vectors as my simulation knows them :
Posted Image

I hope it is self-explanatory and explicity enough. You can see the values i found for the car X/Y velocity, the ones of the wheel after 30° steering and the associated slip angle (30°).

I think everything is ok until there, but if not, please let me know.

Example 2 : now the car has no velocity but is spinning on itself. I made a video so it is easier for you to see what is happening i guess.


Example 3 : will be exactly the same thing as #2, but with the car being moving in a fixed direction AND spinning on itself. Remember, response forces are deactivated so the car is free to do crazy move. I'm just measuring values here.

In first case, the car is not moving fast enough forward before i apply the angular velocity, so the main friction force is here to slow down the car yaw


In the second case, the car has more velocity before starting to spin on itself, so the tire friction tries more to slow down the car. The lateral response vector (the great black vector coming out of the screen) change side accordingly to the car orientation and direction of travel.


I noticed the black response vector sometimes switch side too late, when it reaches 6 o clock. It may be important or not, but i am sure to use the right tire coordinates, so may be more important as it seems ?


The examples i posted here seems to be OK to me, but when i try to apply the calculated forces, the car implodes because of too high constraints (sort of). It doesn't work. Actually, depending on initial heading of car, things happens differently... Which is odd and reminds me of the very first hour of my simulation when nothing was stable and was doing very silly vector/angle/physics engine miscalculations. For example, i use box2d which does not have the same coordinate system as my sim, it can sometimes be confusing.

Before going further into the problem and the questions i may have, i was wondering if someone could have a look and says if something seems really wrong or if it seems ok until there.

Any help will be much appreciated ! Thanks !!!