Jump to content
  • Advertisement
Sign in to follow this  
Rapha

Car Simulation Headaches Part_#2

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :

  1. Start with the car local velocity
  2. Get world velocity of the car
  3. Get the world coordinates of the wheel you want to calculate things for
  4. 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.[/quote]
  5. Convert the point velocity in car frame if necessary.
  6. FInd unit vector in front/side of the wheel, and rotate them according to steer angle of the wheels.
  7. The previous point velocity vector is projected on unit vectors to find front/side velocity.
  8. 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.
  9. The X value of the projected vector on side is the lateral velocity (signed), same goes for the longit velocity with Y.
  10. Positive X means the wheel is moving to the right.
  11. Positive Y means the wheel is moving to the front.
  12. 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.
ct_alphas.gif

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 :
forward4mpssteerright30.jpg

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.

[media]
[/media]

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

[media]
[/media]

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.

[media]
[/media]

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

Raphael Edited by PochyPoch

Share this post


Link to post
Share on other sites
Advertisement
Hello PochyPoch.

I havn't read all of your post but a quick glance brought me to question 4.

To clarify Part 4.

If the car is stationary and spining on it's axis, and the front wheels arn't turned to any steering angle (yaw) but pointing in the direction the chassis points, then each wheel generates +- 90 degrees slip angle. The wheels only have lateral movement. ie they are only sliding sideways as the car spins.

The sign of the slip angle depends on whether the car is spinning clockwise or anti clockwise.

My statement about not generating slip angles was because the car is stationary and no slip angles are generated from the code that uses linear velocities of the car chassis to determine the slip angles. My basic method was using 1 wheel (chassis) to determine the slip angles and Bmarci was using 4 wheels.

Slip angles are generated by the difference between the longitude and lateral velocities of the tire.

The confusion comes from the fact that i was using the car chassis to determine the slip angle and not for each tire.

So when writing your sim, you need to take into consideration the angular velocity of the car and the slip angle that generates for each wheel and the linear velocities of the wheel (chassis , since the wheel is attached to the chassis).

The car can be moving with no angular velocity (moving forwards or sliding sideways), stationary but spinning on it's axis or any combination of the two.

And both situations need to be considered to determine your actual slip angle for each wheel.

The steering angle of the front wheels also needs to be taken into consideration for the front wheels slip angle.

Hope thats clearer.

And best of luck with your game.

I too have made a top down racer.

http://www.trinosis.com/ Edited by K_J_M

Share this post


Link to post
Share on other sites
Hi, K_J_M !

Thank you for your answer ! I already downloaded your top down racing game, but haven't had many time to play it yet ! It seemed a little hard to me at first sight smile.png

If i understand you, then a static but spinning car would generate velocities for tires that would be with 0 longitude, and some value in x depending on the direction of rotation. Something like that : http://en.wikipedia....circular_motion

I found it to be true if the tire is aligned with the radius of the circle. As the wheels are not centered, but rather on the side of the car, when they are not steering, then the radius from wheel attach point to car CG will not be perpendicular to the wheel heading.

If you draw a path following the front right wheel positions, it is indeed a perfect circle, and the velocity of that point (blue vector) is indeed tangent to circle. But as my wheel is not aligned with the radius, the projection of the velocity according to steering (wich is 0), will give me both lateral and frontal velocities, wich in turn will give me a slip angle not equal to +/- 90°. The only case i have such results is if :
a) There is only 1 front wheel, centered on the chassis (like a bike, or tricycle)
b) The wheel is aligned with the radius coming from CG
c) The car is sliding lateraly

circulatpath.jpg

That is a little confusing to me, so i am wondering if :

  1. I should have 0 longitidunal velocities as long as the tire is describing a circular path, regardless of wheel steering. The steering would then be "used" in slip angle calculation like the formula from marco suggest it :

    slip = Atan(latVel / |frontVel|) - signOf(frontVel) * steerAngle

  2. I should have a longitudinal & lateral velocities (excepted for previous a,b,c cases) and my calculations are OK until there (the wheel front/lat velocities are the green and red vectors on the picture).

I am suspecting it is not the only thing that goes wrong with my simulation but it would really helped me to know which way is the right one smile.png

And again, thanks for your help, it is much appreciated ! Edited by PochyPoch

Share this post


Link to post
Share on other sites
It seems to me you are looking at the issue with regards to world coordinates.

If you look at the issue with regards to local car coordinates then each wheel has 0 longtitude velocity and (N) Lateral velocity if the car is spinning on the spot.

Marco Monsters car physics tutorial performs the world to local coordinates transform by rotating the linear world velocities by the yaw angle of the car / wheel.

s = Sin(yaw_angle)
c = Cos(yaw_angle)
local_lateral_velocity = (world_x_velocity * c) + (world_z_velocity * s)
local_longitude_velocity = (world_x_velocity * -s) + (world_z_velocity * c)

And to transform back from local to world coordinates. ( Note the sign for the sine command is reversed, which reverses the direction of rotation )

world_x_linear_velocity = (local_lateral_velocity * c) + (local_longitude_velocity * -s)
world_z_linear_velocity = (local_lateral_velocity *s) + (local_longitude_velocity * c)


But in regards to a stationary car spinning on it's axis the lateral wheel velocity is derived from the car angular velocity. Edited by K_J_M

Share this post


Link to post
Share on other sites
Hi PochyPoch,

Here are some remarks that helped me to get it, if not even right, but an acceptable result :)
1. Create transform functions between coordinate systems (World, Car, Wheel) and double check if they produce the wanted results.
2. Calculate everything in its own coordinates, eg: wheel forces in wheel space, car forces in car space...etc
3. Forget about steering angle in slip angle/ratio calculations. If you have the right transform functions, that will take care of steering angles.
4. Check the result of the ATAN(lat/long), especialy when dividing by long=0!!! The result should be +-PI/2

This is my transform from WORLD to WHEEL, in case of velocity:

angle = -car_yaw_angle-wheel_steer_angle
sn = sin(angle)
cs = cos(angle)
vel_x = cs*world_vel_x + sn*world_vel_y
vel_y = cs*world_vel_y - sn*world_vel_x

(X+ right, Y+ forward/up)

In the last video of your original post (around 0:20) I see something like: timestep = 50/1000
Be careful with this large timesteps, it can cause stability problems with integrating.

I hope I didn't confuse you too much :)

Share this post


Link to post
Share on other sites
Hello to both of you !

Thanks for your detailed answers. As always, i really appreciate it.

I worked very hard those past days on the simulation, and made some progress.

@K_J_M & @bmarci
If you look at the issue with regards to local car coordinates then each wheel has 0 longtitude velocity and (N) Lateral velocity if the car is spinning on the spot.[/quote]
That is right, but when i look at a point in a system, i use my pointVelocity method which takes angVel in account like you said
But in regards to a stationary car spinning on it's axis the lateral wheel velocity is derived from the car angular velocity.[/quote]
So, theorically, when spinning on itself, any point velocity depends on angular velocity of the car. That velocity will be tangent to rotation circle and depends on distance to CG. The wikipedia page illustrates this very well : http://upload.wikime...cceleration.PNG

So i have something like that :
pointvelocity.jpg

So, now, what bmarci said is exactly what i'm doing :
1. Create transform functions between coordinate systems (World, Car, Wheel) and double check if they produce the wanted results.
2. Calculate everything in its own coordinates, eg: wheel forces in wheel space, car forces in car space...etc
3. Forget about steering angle in slip angle/ratio calculations. If you have the right transform functions, that will take care of steering angles.
4. Check the result of the ATAN(lat/long), especialy when dividing by long=0!!! The result should be +-PI/2[/quote]

That's exactly the way i do things. So that means, i am transforming the point velocity of the wheel (the blue vector on the picture) in wheel coordinates, which as we can see it on the picture will result in both lont/lat velocities, and so in a slip angle which is not 90° when the car is spinning on itself.

So the conclusion is in contradiction with what KJM stated above, but i can't see what is failing in my reasonment. Am i right to not find 90° for a wheel which belongs to the right place on a car spinning on itself ? The point velocity seems good, so if i am supposed to get only lateral velocity, i need a sort of hack, or maybe stay in car coordinates instead of going into wheel system ?

The thing is, i am almost sure i am right on this and that my slip angles are good, because the wheel produce good damping forces to annihilate car angular velocity when spinning on itself. If tires produce 90° slip angles when the car is spinning the car is slowing down of 99% and not 100%.

If my slip angles are good, that would mean that my car problems during cornering lies somewhere else. As i said i have obtained a better result, but i am not sure if my base calculations in slip angles are OK. So i cannot really try to tune pacejka or other things like wheel velocity and weight transfer if the underlying system is not good.

Actually the result i have is very close to the Java source example you can download on marco's website. It seems ok as i have deactivated everything else : weight transfer, decreasing pacejka curve, no more real engine/wheel transmission / rotation. I needed to have a clean working table, sort of.

But when i try the car on my game track it is far from playable. If i use an always increasing, producing high cornering forces curve for lateral pacej, then the car turns very sharply, and i can have somme controled oversteer, but the car will eventually stop in the turning curve instead of keeping some speed.

If i use a realistic pacejka curve, then the car is understeering at high speed, which is good, because i can do high speed turns in a comfortable way. But, if i want to produce oversteer and drift for a sharper curve, it just doesn't happen.

So, what do you think ? Problem in base system calculation ? Pacejka curve tuning ? Maybe i should reactivate some critical feature or system ?

I will try to cast a video of the car later to show try to show you, if interested.

Thanks for your help, my game really needs it smile.png

Sorry for the long posts by the way...

EDIT : the main thing here, might be this "the car will eventually stop in the turning curve instead of keeping some speed".

I have the feeling that when i take a sharp turn, even if a great part of the initial velocity will be killed by the lateral forces, and even without pushing throttle, the car should keep more front velocity to come out of the curve. Instead it just stops there with very small to none forward velocity. If i could have this, and manage somehow to mix the best of the 2 results i have with my different pacejka, the game would start to be fun i think.

EDIT2 : those results were obtained with a dummy traction circle (allowing 2*weightLoad traction max), applied only on lateral force for testing purpose. Edited by PochyPoch

Share this post


Link to post
Share on other sites
Oh, and i have one more question that has haunted me those past days.

Knowing that marcos slipAngle formula is made to be used with car coordinates (that's why it takes angular vel, and so) to determine the lateral force the tire produce, it makes sense that this lateral force should be applied to the car directly perpendicular at wheel position.

But, i use a formula where the front/lat velocities are the real ones of the wheel. So, simply using this formula should work to determine slip angle :
var alpha = -Math.atan2(wheelRealSideVelocity, Math.abs(wheelRealFrontVelocity));


But when it comes to applying that lateral force...
Case 1 : Should i apply the given force perpendicular to wheel, with steering producing an oriented lateral force, which will slow down the car ?
Case 2 : Or instead should i apply it perpencular to wheel attach point, regardless of steering, and then it will only make the car turn, but never slow it down ?

Case 1 example :
lateralforceappliedonti.jpg


Case 2 example :
lateralforceappliedonbo.jpg

Everyone use its own formula and coordinate system in the examples i have found, so it is not clear to me.

For Slip Ratio, it is more obvious as we look at patch speed (wheel angular velocity) and ground speed in the direction the wheel is heading, it seems logical to have that vector acting in the wheel space, thus respecting steering angle.

But using a simplified formula with examples were it is used to apply a force directly perpendicular to car makes me have some doubts... Edited by PochyPoch

Share this post


Link to post
Share on other sites
Hi.

The Pacejka formula's work in wheel local coordinates.

Longtitude pointing in the direction the wheel rolls in and Lateral at 90 degrees to Longtitude direction.

So,as i understand it, Case 1 Example is correct.

Although i'm no expert, i always understood that a stationary car spinning on the spot with the steering centred produces no longtitude forces from the tires to move the car forwards or backwards. But only lateral forces to slow down the rate of spin.

But, maybe someone with more detailed knowledge than me can give a more accurate explanation.

Share this post


Link to post
Share on other sites
Hi,

That's bad for me because i get much better results applying the lateral force directly to car chassis regardless of steering angle (but i take it in count for slip angle calculation). Maybe i just need to tune pacejka curve to respond to the fact it changes the car behaviour somehow. A little change alway seems dramatic in result at first, but maybe it is the right way to go and i need to adapt my curves which are really trivials for now.

Although i'm no expert, i always understood that a stationary car spinning on the spot with the steering centred produces no longtitude forces from the tires to move the car forwards or backwards. But only lateral forces to slow down the rate of spin.[/quote]
As i understand it, when wheels are centered, the lateral response will be perpendicular to wheels, and will then slow down car rotation, but it will not introduce longitudinal force. The longitudinal force component present on the wheel during spinning will just introduce a diffrent slip angle result.

I re-checked marcos page for the steering section. He claims, after determining lateral force using pacejka curve, that they have to be applied to the car body. He will apply both lateral forces directly to car body, and then use them separatly to calculate torque and finally introduce some yaw. Fine for me, but what does he have to say about the lateral component of the front wheels ? This :
The lateral forces of the four tyres have two results: a net cornering force and a torque around the yaw axis. The cornering force is the force on the CG at a right angle to the car orientation and serves as the centripetal force which is required to describe a circular path. The contribution of the rear wheels to the cornering force is the same as the lateral force. For the front wheels, multiply the lateral force with cos(delta) to allow for the steering angle.[/quote]

Fcornering = Flat, rear + cos(delta) * Flat, front

I'm quite rusted with my trigonometry, so i'm not 100% sure, but i think that will act as if the lateral response IS indeed perpenducular the the wheel, according to steer angle, BUT that he is suggesting to take only the force component that is projected on the car side axis. So if the front wheels are centered, 100% of the force will be applied. But if the wheel is steering at 60°, only 50% of the force is applied to the car.

But he is only calculating centripetal force and torque, so i guess only the truly lateral component does it. He may have "forget" the sin(dela)*Flat, front which is supposed to slow down the car as it is cornering, but maybe it is not that important for the car behaviour ? If i release the gaz pedal, it may slow down the car by a similar amount. If i'm right, that would mean, that i just should try to have better steerAngle/steerSpeed/lateralCurves constants instead of looking at the maths.

---

One other question as i'm experimenting if i may :

Do you know if traction circle should be applied before or after taking count of weight load ? Because when i slow down the car in/before curves, so much weight get transfered to the front that the lateral force increase happens way too fast and the car can make an half-turn really easily. I feel like traction circle should be capped at some maximum load or maybe my weight transfer needs a real spring instead of a simplistic time integration of the weight transfer.

By the way, it feels a bit strange to me that only weight transfer due to +/- acceleration affects cornering capacity in curves. Am i missing something here or again, should i just tune weight transfer speed to get something smoother to drive ?

EDIT : after re-reading closely PHORS articles, it seems only acceleration/weight transfer affects available traction and it is supposed to scale linearly with weight load, indefinitely. http://phors.locost7.info/phors07.htm

---

Thanks for your help and sharing your experience ! You say you are not expert, but given the quality of your racing game, i'll take your advices very seriously ! It's exactly the kind of feeling i want, only more arcade-ish. Edited by PochyPoch

Share this post


Link to post
Share on other sites
Thanks for the comments.

Both Long and Lat Pacejka formulas need FZ (load) as one of the inputs.

And a resulting force as output.

The traction circle caps the forces to a maximum limit. I think the Racer sim reduces Longitude forces in favour of Lateral as a way to cap the forces.

But there are several different methods that i've seen.

Since the traction circle limits forces, and these are calculated from Pacejka which requires FZ (load) as an input, the traction circle caclulations are applied after the forces have been calculated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!