So does anyone know some good alternative methods of dynamic friction, instead of the unitys own car tutorial method?
As i have noticed in unity’s car tutorial, the extremum and asymptote values for both sides(forward sideways) are changed by cars lateral velocity only, and the numeric values dont look realistic, i mean 300 and 150 arent really a real life values, but they work somehow… anyway i was thinking, if someone knows some better and a bit more realistic solutions for dynamic wheel frictions and would be kind enough to share their solutions?
Or if i could figure it out myself by some hints and help from other users?
So here is my theory:
I’ll start with the sideways friction first (because visually this shows more effect, drifting powersliding spinout etc.)
extremum Slip = 6 ← this is the peak angle (in degrees), where the sideways friction is at it’s most griping value
extremum Value = 1.00 ← this is the normalized force so 1.00 means 100% of the available grip is used in 6 degrees
asymptote Slip = 20 ← this is the second peak angle (in degrees), where the sideways friction is at it’s “sliding” value
asymptote Value = 0.60 ← this is the second peaks normalized force so 0.60 means 60% of the available grip is used in 20 degrees
Stiffness = 3000 ← so this is the available friction value, since this scales the whole friction curve, this should be dynamic, for a dynamic sideways friction i think the slip angle and wheel normal load should be used to change this value dynamically, but i am not sure on how to use this in the right way, i always get unrealistic results…
So thanks for reading, helping posting solutions(hopefully), and ignore my bad english, i am from estonia.
As far as I know stiffness is literally just a multiplier so I guess by the Commutative property you can reverse them if you want. But if I’m not mistaken, it will not change it’s behavior.
When you say “for a dynamic sideways friction”, If I’m following you, I believe you have noticed the same thing I have. It appears “sideways” and “forward” slip are not connected in any way. This is a huge problem. I experimented for a few minutes last night with connecting them by decreasing stiffness of one as slip of the other increases but got counterintuitive results. If I’m not mistaken friction is already scaled by normal force - at least I would hope it is - but I do have the same concern.
Have you been able to confirm that Torque is in Nm? With realistic masses and center of gravity, what I’m seeing seems to indicate that it’s nearly off by a power of ten… which would lead me to believe it might be in Kgm but that’s just silly.
Iv’e read somewhere that unity uses only 2 flags in physx wheel collider, NX_WF_INPUT_LAT_SLIPVELOCITY and NX_WF_INPUT_LNG_SLIPVELOCITY.
I am not sure if this is true, but if it is, then only lateral and longitudinal forces are used for the friction curve. If i’m right, this means wheel load is not used…
The stiffness value seems to be the only thing logical to be dynamical. Because after reading and testing, this value scales the whole curve (this means, yes it multiplies the extremum and asymptote values) just like in pacejka formula the wheel load does. But i think that simply placing wheel load to the stiffness factor, will not do the trick, atleast i tried it once and it didnt work very well …actually it messed everything up haha.
Maybe forward and sideways stiffness factors should be in a friction circle function?
I think in pacejka formula its called “combined pacejka” or something like that…
One simple combining method is described here: Pacejka Magic Formula
It cuts down one of the forces so that they dont exceed the maximum friction available for one tire…
For torque, i currently use a very very very basic driveline just to get the car to move with gear ratios and a torque constant, also forward friction may limit the torque in some way… but this is not the thing i am aiming right now, i simlpy want the wheel friction to act better then just constant curves.
I’ll admit I was picking up on that last night (The normal force not being calculated) but I decided that surely they couldn’t ignore something so basic. And yes I also found that simply using normal force to scale stifness didn’t work because as one side of the car is loaded the friction runs away with itself and suddenly you’ve got way way too much traction on that side: you are effectively ignoring the friction curve.
I think if you limit the amount of stiffness you can add beyond 1x quite a bit, e.g., 1.15 maximum - but allow it to decrease down to 0 as normal approaches 0, you might get more realistic (but still stilted) results.
exactly thats my point haha, anyway i just wrote few scripts to siplyfy car configuring but still cant get the realistic friction that i am aiming, and yes the torque value seems to be off by 10, i just noticed it myself haha, anyway i also added “private var D2R : float=(Mathf.PI / 180);” and i multiply the sideways extremum and asymptote slip with it, so the values should be a bit more real now, the stiffness is 500.
But then again at higher speeds the car doesnt spin out it still just clamps to an angle, it could be alot better if at higher lateral speeds the stiffnes decreases, and im not sure what forward friction does then, increases, or does this also decrease?
Unfortunately I have studied tire physics very little. Obviously you can’t simply approach it as though it’s a friction coefficient because it’s not simple friction but cohesion, which is where the wheelColliders friction curve comes into play. However my experience tells me that for very high longitudinal slip rates, lateral friction goes nearly to zero (at least for low lateral slip angles). e.g., if you’ve ever watched drag-racing, a person can push a car sideways by hand with very little force while it’s doing a burnout. Do you suppose this is related to why we aren’t seeing the lateral slip we expect?
I’m afraid I don’t recognize what you are accomplishing with “PI / 180” - I recognize pi as the radian equivalent of 180 degrees but why you would divide radians by 180 I don’t know?
With that simple value i convert degres to radians, it seems to me that the “slip” values are in radians, because if i but degrees into the slip places, the car nearly turns…
Anyway with drag racing and burnouts, when a tire is doing a burnout aka accelerates, the slipratio of a tire is 1.0 or higher (depending on the tire speed and road speed) the oposite goes for blocked braking, when road speed is higher then tire speed.
Well from this fact i think that slip ratio is also used for the calculation of caombined lateral speed … uhm the awkward thing to me is, that in pacejka formula only longitudinal force takes the slipratio in…
Anyway i did some more tests, and when i multiply hte engine torque with 100 and decrease the longitudinal stiffnes by 10, i get better steering, dont quite understand the connection here…
“With that simple value i convert degres to radians”
DOH! lol how embarrassing =/ What can I say I took trig and calculus like 6 or more years ago.
by the way, Mathf.Rad2Deg and Mathf.Deg2Rad are built in… it could save you a line of code I suppose =)
anyhow, I’m still nearly certain that something more complex occurs to lateral friction when there is a high longitudinal slip. Like the burnout example, if you consider high longitudinal slip rate during braking (the locked tire situation you mention) the same thing occurs! if you lock the rear tires, the back of the car will slip laterally (at least for very low lateral slip rates) with extremely low lateral forces.
oh i forgot that they were built in haha, it’s because i am also programing in c++ just to learn physx a bit more and see if i could get better results without unity, but to be honest changing flags in c++ code didnt give any noticable changes i think its just the way physx has ben built up, the curves are constant and they are just readable, so the curves must be changed dynamically to get semi realistic results.
Someone over the physx forums sayd something about using slipimpulses, but those imuplses are something that i dont understand in no way, they arent slip ratios or slip angles, they are just some impulses, do you know whats the best usage for them? Because id rather work with slip angles and slip ratios instead of some unknown infinite forces …
I don’t know them, to be honest the WheelCollider is limited in so many other ways I don’t really intend to use it. I would just like to get it working better to use as a place holder until I’m further along with this project. We need to convince ArnoldWong to work with us (READ: Give us his code! LOL). Check out his pacejka based WIP if you haven’t seen it: http://forum.unity3d.com/threads/87166-My-first-Unity-Racing-game
I was impressed. My initial reaction (without having played with it) is that the tire model looks pretty sweet.
Well i know that wheel colliders can be used pretty good actually, if you have played mafia II (they use wheel colliders)
anyway when you want to use pacejka, then unity tutorial has an alternative example also, it uses pacejka, and if you tweak it wisely youl get very realistic results.
I’m trying to avaoid using pacejka right now because it has too mani variables to change, and it’s to realistic haha, i want fun realism like in gta 4 or mafia II
Anyway i saw that video earlyer today, and i can say that it’s probably playable with only steering wheel (because of the realistic pacejka use) so it’s real but fun is lost, i’l change my mind if i can actually get my hands on that little racing game hehe, a source would also be nice yes!
The wheel collider is actually very good, but not perfect. I am actually writing a tutorial on car physics and getting everything setup. The dynamic wheel friction is totally possible, and I actually implement that into my model in the tutorial. It more has to do with the AnimationCurve in Unity than large math formula’s. It is not perfect though. You can use the method to greatly achieve anti roll in the simulation.
The biggest problem that I have seen with the WheelCollider is the lack of physics material affect. So if you were driving on ice, with no actual math, you couldnt tell you weren’t driving on anything but asphalt. This too will be addressed in my tutorial.
Using the AnimationCurve to store/interpolate is an interesting idea. I would suggest that a lot of the numbers and calculations you are using are a bit wacky. e.g., your using 240HP as a starting point for your power calculations but you are actually then plugging a multiple of this number into motorTorque which does not compute. Power simply does not = Torque so you can pretty well throw the 240 number out of the window (although 2001 z28 was actually a bit over 300hp.) It appears you are compensating for the lack of a transmission simulation by putting the peak “power” much lower on the “power curve”, meaning the power curve also doesn’t have much basis in reality. At least not as a power curve - it’s a bit closer to the torque curve you might see at the rear wheels of a car with a transmission though. Also fair to say that F1 cars at speed might not quite have the road holding power your car does.
My point is that you note how much time it takes to tweak these numbers to feel right and that’s exactly my problem with the way most people use Unity. The prevailing notion on the forums that you don’t need to worry about units and you can use whatever units you want feeds right into this. For one thing, if you use Pounds for mass, Pounds for force, and Feet for distance, set your rigidbody to 2500"lbs" and apply 2500"lbs" of force, you’re screwed. No question - you might be working with a physics simulation but you don’t have a physics sim, you’ve got garbage operating in a physics simulation that will then give you garbage back. You will immediately find that 2500 force doesn’t do much and so begins the “tweaking”. Unity should do everyone a favor and put an asterisks next to every post that claims you can just use any unit you want willy-nilly. While they are at it, go ahead and label every unit so there are no more guessing games. I’m sure they are trying to avoid scaring people or offending english-unit users (and don’t get me wrong, I love my english units but only because I grew up with them… they are seriously stupid for doing physics) If you do your math right the first time you can just put in realistic values and skip the hours of tweaking by and large unless you are trying to make an arcade game without much basis in reality - in that case tweak away.
If you were looking for constructive criticism I would offer that, as a sanity check for your calculations, it’s probably worth noting that cars typically don’t become airborne after a four or five seconds of acceleration, certainly not 240hp cars. You’ve got a better simulation of a wheeled rocket ship right now. And from a fun AND realism standpoint, most cars stop quite a bit faster than they accelerate. A 911 Turbo in a C&D test, for example, does 0-100mph in 9.4 Seconds but goes from 100-0 in only 4.3. The differential between the two times actually becomes more extreme on more lowly cars.
…and since I’m thinking about - if anyone is looking for a braking curve - it’s not really going to be a curve. It’s mostly linear. Yes engine braking isn’t linear but it’s truly negligible compared to braking force and everyone should be using a separate wind-resistance calculation anyway so you can ignore that too.
tl;dr: Use a static braking force * normalized controlinput.
I do like how you separated engine braking from braking though, MisterB - it would be infinitely more realistic with a transmission and a power simulation though.
MisterB method is interesting but i think it’s not what i am looking for, its more like jumping between values… atleast the demo didnt reflect the reactions that i expect from a car.
What comes to wheel colliders, i am sure they can perform pretty good if the dynamic friction part is figured out, i mean for example GTA IV, Race Driver GRID, they use the same hermetic curves, that Unity3d uses(actually PhysX, because this wheel collider “issue” is not only unity3D related, it also occurs in c++) The only difference is that In those Games there is allready a Dynamic Friction model that includes low speed frictions and friction combining (because they are complete games doh lol) Now it’s not a PhysX based issue, as people think, because in Mafia II there is a solution, but its hardcoded. They are basically the only developer team that have used their brains wisely while using physx to create vehicles hehe (atleast i dont know any other games that has physx vehicle support this great).
I am pretty sure that there is actually only 4 or maximum of 8 lines of code that will do the realistic trick of combining and cutting the friction curve forces, like it’s done in gta IV or GRID or mafia II or in any other arcade game that involves car physics that look and feel good and are fun to play at the same time. After all gaming was ment to be fun instead of getting mad over your to realistic steering wheel hehe. (to be honest i am sure wheel colliders can also be used in a simulation, since after all pacejka and hermetic curves are very simmilar, actually hermetic is just a simplyfied pacejka)
The next biggest limitation for me (since I am not exactly dealing with racing) is that they operate on only a single ray. Realistically this just doesn’t work for me. I need a collider for all (or at least most) relevant parts of the tire.
Also, I don’t believe there is any way to get exact suspension position back out, it can be calculated easily so long as the wheel is grounded but if it is grounded and then ungrounded instantly (off a ramp for example) it is not possible to show the damping effect without doing your own calculations a 2nd time ( to the best of my knowledge ), you are forced to allow the wheel graphic to snap to the lowest position.
By the time you address that limitation and consider adding different rebound and compression rates… it’s just not worth it anymore, the only thing it has going for it is the built in very basic tire model that has to be patched up anyway (and actually I think even their curve is a little suspect) for all but the most rudimentary driving “sims”. Also adding mass beyond 1 seems to break my motorTorque input and I suspect unsprung weight wouldn’t be handled even if it did work. Obviously you’ll have to handle camber/caster and such on your own as well… I have more concerns but these are the few that come to mind right away.
It’s fine for an arcade racer but keep in mind that there are people like me who have a very very hard time enjoying anything that’s not a pretty serious sim. Funny you mention GRiD, I drove the car about 30 feet and uninstalled. When I started this project I had intended to stay far away from sim-realism as I knew it would be difficult but I find that I can’t help myself. I know there are people who don’t enjoy sims at all but there are quite a few of us who love it and won’t have it any other way. I hope I’ve got them covered =)
hehe, grid is nice for arcade drifting. Anyway i like sims and arcade, i like sims to see how i can handle it and i like arcade for the fun i can get, anyway, if you are aiming at sim’s, then i recomend you to thake a deep look over the alternative physics model, that comes with the unity car tutorial, it needs alot of tweaking to be a great sim, but you have all the sim advantages.
Basically it’s a replacement for physx wheel collider. It’s also a wheel collider but the friction model is pacejka96 and you can controll everything over the ray. For example i took the charger prefab, raised the center of mass, removed traction controll, lowered the suspension forces and made some donuts and burnouts. It could be a good base for a sim project.
Also you mentioned the collision of a tire, well physx has sugested a solution for this. Simply place a convex rigid body at the wheels position, and set the friction to zero. This way you can simulate the collisions and real massing of a wheel.
Camber/Toe/Caster …well i dont think that they are much of a problem, since they are simply just angles.
Also If you want more realism you may concider using Dof6 joints + rigid bodys for collisions and rays for friction, this way you can get the best results for a sim type of a game.
Anyway back to the point why i made this tread lol, i simply want to know if anyone knows a great ultimate function to cut and combine the friction forces, lateral longitudinal, just to get semirealistic tire physics running
I have been pondering what we could use in place of the wheel collider that would give us a round wheel. Mostly because I was looking at building a true monster truck. With no cylinder collider it makes it a bit tough. I have come up with a plan though use a Sphere trigger, and use the code from Forest Johnson’s Carpakke2. It’s not Pacejka, but it does look pretty snazzy. The code would have to be adapted for a sphere object, not just a ray. The cool thing is that you give it a width, then ignore all the collisions that are past the local width of the tire. It would cause wholes in the sides, but we would get a true round tire out of it.
interesting solution, feels quite nice but i dont quite understand the values, it looks like everything is quick and linear, good for a fps game with vehicle suport, but for a actual car game, hmm maybe il try to do a “realism” test with it and see how it would handle a drifting nissan 350z