Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to implement tire friction?

Discussion in 'Physics' started by unity_44234FBC39E5661FBF5B, Nov 9, 2021.

  1. unity_44234FBC39E5661FBF5B

    unity_44234FBC39E5661FBF5B

    Joined:
    May 11, 2021
    Posts:
    29
    I'm trying to make my own wheel collider. I got stuck on how to add friction. How would I add friction (like pacejka)?
     
    tehmainespartan likes this.
  2. unity_44234FBC39E5661FBF5B

    unity_44234FBC39E5661FBF5B

    Joined:
    May 11, 2021
    Posts:
    29
  3. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    To add wheel friction to a raycast wheel you need to:
    • calculate the velocity relative to the wheel's normal (it's right facing vector)
    • add the negated side velocity, you can use a curve here to control how much based on any factor you'd like
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,428
    I'd recommend you to implement the simplest possible friction first: a coulomb friction based on the downforce and a coefficient of friction. In the case of a wheel, such friction would work permanently in the sideways direction of the wheel, and it would also work in the longitudinal direction when the wheel is braked.

    Wheel friction is a HUGE topic, and simulating it can be as complex as you want. Pacejka (also "magic formula") is not a friction simulation, but just a trigonometric curve y=f(x) designed in a specific way to produce a shape that resembles the friction curve of a tire. Any curve or function with a similar shape, or even a constant coefficient of friction, will work. The implementation of the tire friction itself is much more important than the actual values you feed the coefficient of friction with.

    For example, the latest iteration of my tire friction simulation model was designed with the guidance of an engineer who works for a top level racing team (F1, Formula-E). This model doesn't use Pacejka. Instead, it implements a parametric cubic curve that produces the same results but is much easier to configure to fit the actual tire behavior.
     
    Last edited: Sep 19, 2023
  6. unity_44234FBC39E5661FBF5B

    unity_44234FBC39E5661FBF5B

    Joined:
    May 11, 2021
    Posts:
    29
  7. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    Ah, I did not know you could not read the scripts there, sorry.

    I think the reason you are perhaps not getting the exact guidance that you want is already touched on by Edy - implementing a good tyre model into Unity is a complex task, there is no simple step to go from Pacejka data to a working tyre model. You will have to experiment, starting simply and working up. Unless you are very confident of your physics modelling and vehicle dynamics, I would suggest that you would be much better off using something already out there (I know I would).
     
  8. unity_44234FBC39E5661FBF5B

    unity_44234FBC39E5661FBF5B

    Joined:
    May 11, 2021
    Posts:
    29
    so I managed to add friction, but only to the sides. It still slides forward even if no input is pressed.
     
  9. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    I have one simple question: Does Unity Wheel Collider have Pacejka?
     
  10. driftnumata

    driftnumata

    Joined:
    May 31, 2023
    Posts:
    29
    No, if you wanna use Pacejka using unity wheel collider, you need to control the wheel forces in the script.
     
    Davidbillmanoy likes this.
  11. Davidbillmanoy

    Davidbillmanoy

    Joined:
    Jul 7, 2014
    Posts:
    119
    Can anyone tell me how to control the wheel forces? And what script?
     
  12. driftnumata

    driftnumata

    Joined:
    May 31, 2023
    Posts:
    29
    First, set the all wheel friction values to 0 (You can make zero friction wheel colliders)
    And finally, add the wheel forces (except suspention force) using rigidbody's AddForceAtPosition() in script. (Sorry to my poor explanation)
     
    Davidbillmanoy likes this.
  13. Anikate25

    Anikate25

    Joined:
    Sep 17, 2023
    Posts:
    3
    First, understand the Pacejka model and gather tire data. Then, implement the model's equations in your code, applying friction forces based on slip conditions. Integrate this with your vehicle simulation, test thoroughly, and fine-tune parameters for realism. It's a challenging process that requires both physics and programming knowledge.
    if you are still not clear feel free to ask.
     
    Davidbillmanoy likes this.