Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

WheelCollider WheelHit.force mystery

Discussion in 'Physics' started by NDSno1, Mar 3, 2018.

  1. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Hi all,
    So I'm still on the quest of understanding wheelcollider, and stumbled upon wheelhit.force. The API doesn't explain very well, as it only says it's the force at the application point, but not mentioning what kind of force. So does anyone know what force is this? Is this suspension force acting on the wheel, representing how hard the wheel is being pushed to the ground? Or is this the actual net tire force that drives the vehicle forward, tireforce - rolling resistance?
    Also I'm starting to understand the wheel friction curve. I'll try to put everything in place and share my guess and understand on the forum.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,212
    It's the vertical suspension force acting on the wheel.
     
    NDSno1 likes this.
  3. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Thanks Edy.
    I came up with this question after looking at WheelColliderSource from UnityCommunityWiki, where the totalForce value, exposed as WheelHit.force is the sum of both lat tire force, long tire force and suspension force.
    Well I was hoping that I can somehow extract tire force to convert to tire torque, guess I have to find some other way.
     
  4. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,058
    (Disclaimer: I don't work with Unity wheel colliders so Edy will for sure know a lot more about them than I do. Listen to him on wheel colliders, not me. This post also assumes that this is the same code that Unity is using. I have no idea if that's the case.)


    I'd be surprised if it wasn't just the vertical force like Edy said, but per your link it looks like it might indeed be the full force vector if that's actually Unity code.

    GetGroundHit() shows wheelHit.Force = m_totalForce

    CalculateForcesFromSlips() computes m_totalForce as:

    Code (csharp):
    1. private void CalculateForcesFromSlips()
    2.     {
    3.         //Forward slip force
    4.         m_totalForce = m_dummyWheel.forward * Mathf.Sign(m_forwardSlip) * m_forwardFriction.Evaluate(m_forwardSlip);
    5.  
    6.         //Lateral slip force
    7.         m_totalForce -= m_dummyWheel.right * Mathf.Sign(m_sidewaysSlip) * m_forwardFriction.Evaluate(m_sidewaysSlip);
    8.  
    9.         //Spring force
    10.         m_totalForce += m_dummyWheel.up * (m_suspensionCompression - m_suspensionDistance * (m_suspensionSpring.TargetPosition)) * m_suspensionSpring.Spring;
    11.  
    12.         //Spring damping force
    13.         m_totalForce += m_dummyWheel.up * (m_suspensionCompression - m_suspensionCompressionPrev) / Time.deltaTime * m_suspensionSpring.Damper;
    14.     }
    If it indeed works this way in Unity, you should be able to start with m_totalForce and compute the longitudinal force component yourself by doing a dot product with a forward vector projected along the ground plane. With that and the tire radius you could get a wheel torque. If this is right, keep in mind that it could break if Unity ever changes how this works.

    If it turns out that Edy's comment was right and the value you see in Unity is really just the vertical force, ignore this post.
     
    NDSno1 likes this.
  5. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Update.
    I did some debugging today and I found out some interesting things about this wheelhit.force thingy.
    I'm assuming tire force is the torque input to wheel, times friction curve value at current slip, sort of like
    tire force = wheel.motorTorque * frctionCurve.evaluate(slip);
    For now I'm getting the forward friction force only for debugging.
    Next, I calculated the spring force based on the calculation of WheelColliderSource. Then I took the sum of tire force and spring force, output it to debugging and compare it to Unity's total force result. These are my results. Focus on Total Force, which is my own force calculation, and Force on the next line, next to sideway slip, forward slip, is the result from Unity's WheelCOllider for the current wheel (rear right)

    2018-03-05 (5).png 2018-03-05 (8).png
    Next, I took the sum of spring force and damper force only, from wheelColliderSource, and output for debugging. This is what I got, focus on the 2 red lines:
    2018-03-05 (10).png
    This time, the result is largely different. Also another note is that WheelColliderSource's totalForce and Unity's force increase and decrease inversely in relation to each other. Which means totalForce increase then UNity's force decrease, and vise versa.totalForce increases when the suspension lengthen (when car is braking), while Unity's force decrease in this case.
    So right now my guess is that Unity's force should be something more than just suspension force and damper force, maybe something with sprung mass also (also shown on the above debugging). However, wheelcollidersource was made when there was still unity 4, and mimicking unity 4's wheelcollider, so there might be a lot of changes here and there, and this test is not valid.
    It worth bringing it up here though, people are still very frustrated with wheelcollider, so I hope this might open for other findings.
     
    Deeeds likes this.
  6. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    By this did you mean the dot product of totalForce vector with transform.forward?

    I really really hope that some Unity moderators or someone working on the physics at Unity would bump in here and resolve all of these confusions with wheelcolliders. This has been the problem for so long now.
     
    Deeeds likes this.
  7. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,058
    Not transform.forward. Instead what I meant was construct a vector that's forward relative to the individual wheel and projected onto the road surface and normalized. I.e., the direction of the tire's longitudinal (forward/backward) force on the ground. Add up all four forces and see if they equal the weight of the car when it's sitting still. It'll fluctuate a little bit, some due to damping forces (nothing in a physics sim is usually sitting perfectly still), so just see how close it is. If it matches up within a couple percent most of the time, hit the gas to accelerate the car and see if the hit force grows to include the longitudinal force within an acceptable margin. The idea is to see if the vertical force is really the only force shown by the collider. Edy said it is, but the source you've got includes all of it by the looks of it, but then again it's from way back in Unity 4 as you said so could very well have changed several times by now.

    Personally, I'd forget about all that and just write my own wheel collider and tire model. Even if you figure out how it's working it could change on the next Unity update and break your system.
     
    NDSno1 likes this.
  8. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Hm I'm not quite getting there. Sorry but I still can't imagine the direction of this vector and its magnitude. Are you talking about normal vector like the diagram here:?

    Also Unity's WheelHit.force is a float and is the magnitude of the force vector at the application point, not a vector as WheelColliderSource totalForce, so how does this WheelHit.force float fits into the vector you are talking about?
    I'm really sorry for asking too much like this. I'm really confused right now since I'm not very good with working with vectors without a diagram.

    I'm actually doing that right now. I'm reading racer.nl source code for the tire model to understand how to turn the physics into code implementation. Right now I'm trying to understand how lateral force and longitudinal force are combined, and what is the direction of the tire force vector at the application point, and where to actually apply the tire force. Still a long way to go.
     
  9. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Also very quick, what would be a typical tire force range for a typical road car weighing at around 1500 to 1700 kg? Just for having an idea pf what number I should look for
     
  10. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,058


    Green arrow is what you want. That's the direction the acceleration/braking force acts in. (Cross product of surface normal vector and the direction vector of the wheel about which it spins when rolling.) What I was suggesting is trying to figure out if the hit force is the normal force + that green arrow force or if it's just the normal force by itself.

    Tire force is applied at the contact patch, the beginning of the green arrow. The values depend on how much engine torque you apply and how high it can go due to grip and weight distribution.
     
    Last edited: Mar 6, 2018
    NDSno1 likes this.
  11. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    It seems that I cannot get the normal force, but only normal from wheel collider, since I only got a vector3 (0,1,0) when standing still. And strangely there is no way the get the velocity vector of the wheel either, only the rigidbody.
    Say assuming that the force reported by wheelhit.force is the total of tire force and suspension force, how can I extract the tire force from that single float?
    I also stumbled upon this old thread in the forum, where someone somehow extracted the tire force to prove the wheel collider friction curve implementation is wrong by plotting the tire friction coeff vs slip graph
    https://forum.unity.com/threads/wheel-friction-curve-revealed.153340/
    I'm trying to understand these 2 lines here to see if the friction coeff actually calculated from tire force
    Code (CSharp):
    1. reactionForce = pushForce - (wheelRigidBody.mass * acceleration);
    2. frictionCoeff = reactionForce / hit.force;
    I'n thinking about plotting something like this, but with hit.force instead, to see if the force actually changes based on slip.
     
  12. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,058
    Sorry, there's not a lot left I can do here without just handing equations and code over and doing it all for you. You need to study some vector calculus, at least learn vectors/dot/cross products and get a solid understanding of how that math works so you can visualize and construct these things on your own. Vehicle dynamics and basic physics at least at a high school level need to be studied and well understood too, otherwise you're going to need hand holding the whole way on every little thing.

    I don't think I want to spend any more time on this. Not trying to be rude, but you're at the point where I had to clarify on a diagram what direction traction/braking forces act in relative to a wheel. Differentials/drivetrain modelling is a very long way off from that.

    Time to hit the books!
     
    Last edited: Mar 7, 2018
  13. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    195
    Not at all. Thanks a lot for your help. Now I realized that I need to slow down and step back to study the fundamentals. Working with the limitations of WheelCollider strayed me too far.
     
  14. JeyP4

    JeyP4

    Joined:
    Mar 6, 2018
    Posts:
    16
    Are you sure?
    Because summing up all the 4 wheelhit.force at Zero carSpeed OR steady condition, doesn't end up on car's rigidbody mass. It ends up 1627*4/9.81 = 663.4kg for a 935 kg car rigidbody. I m confused..
     
  15. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,212
    100% sure. You get that result because the underlying PhysX code is shamelessly buggy and/or badly designed. Being specific, the vehicle substeps mess up the force calculations. Configure the vehicle to use a single substep and you'll get the exact result:

    WheelCollider.ConfigureVehicleSubsteps(10, 1, 1)
     
    JeyP4 and Deeeds like this.
  16. JeyP4

    JeyP4

    Joined:
    Mar 6, 2018
    Posts:
    16
    Thanks Edy.
    It was helpful.

    It gave me exact results at Zero carSpeed.
    But it doesn't work when speed ~= 0.
    e.g. while I am accelerating i saw Force values are 2336, 2336, 2332, 2332 (FR , FL, RR, RL respectively) @ 6km/h.
    I mean it is showing almost same values for front & rear wheels.
    This is no logic, it should be more in numbers for rear wheels than in front wheels. (Skycar-RearDrive & FrontSteered)

    I know Edy you have a bad experience with wheelCollider's force results. But, do you think we can rely on slip values?
    And correct me if I am wrong, the sidewaySlip it gives is just the velocity of wheel in lateral direction m/sec !! or some SlipAngle?
    I am dying to find reliable model for Fx, Fy & Fz for every wheel. I know, I asked so many things. I m sorry..
     
  17. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,212
    The precise values depend on a variety of factors: acceleration, center of mass, even inertia tensor may have something to do in some situations.

    I've been unable to extract any logic out of tire friction vs. slip values vs. torques in the WheelCollider.

    I can only recommend Vehicle Physics Pro here. Longitudinal and lateral forces are accurately and predictably calculated based on the tire slip, the normal load and the friction curve. At the same time, the drive torque and brake torque applied to the wheel are correctly combined with the longitudinal tire friction to compute the angular velocity, which affects the longitudinal tire slip and thus the resulting tire forces.

    Here's a brief example on how to interpret the telemetry values for the slip, tire friction and lateral forces:
    https://vehiclephysics.com/advanced...ing-steering-friction-and-lateral-slip-forces
     
    JeyP4 likes this.
  18. JeyP4

    JeyP4

    Joined:
    Mar 6, 2018
    Posts:
    16
    Hey Edy

    Thanks
    Whats the difference between Edy's Vehicle Physics( https://assetstore.unity.com/packages/tools/physics/edy-s-vehicle-physics-403)
    &
    Vehicle Physics Pro ??
     
  19. JeyP4

    JeyP4

    Joined:
    Mar 6, 2018
    Posts:
    16
    Hey Edy

    I find Edy's Vehicle Physics affordable for me.
    Can you tell me which type of steering system it contains?
    I mean relation between left and right wheel steering angle. Is it same angle for both wheels, Ackerman's ideal relation or Jeantaud relation? Anyways I am gonna rig Smart4Two car. So I also need to understand, how to modify tirefriction curve characteristics in Edy's Vehicle Physics also.
    Thanks for considering me..
     
  20. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,212
    Edy's Vehicle Physics (EVP) is a simplified vehicle model focused on ease of setup. In EVP you specify handling-related parameters only: speed, acceleration, tire friction, oversteer/understeer, etc. There's no powertrain simulated. Wheel forces are computed and applied to the vehicle based on the parameters. The tire friction is uniform, so you can only configure the coefficient of friction (no friction curve). Steering angle is the same in both wheels.

    Vehicle Physics Pro (VPP) is a complete and realistic vehicle simulation providing an accurate tire model, a customizable modular drivetrain model, and many advanced simulation features. Check out an overview of the vehicle settings available in VPP here:

    https://vehiclephysics.com/components/vehicle-controller/
     
    JeyP4 likes this.