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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Stop Car Sliding Sideways on a slope (+GIF)

Discussion in 'Physics' started by NoCakeNoCode, Dec 27, 2015.

  1. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
    Greetings

    I have a problem with Unity's Car Tutorial alternate physics model wheels script.
    The issue can be seen in the following gif:



    I've added the following small script to stop it from slipping :

    Code (CSharp):
    1. if(speed == 0)
    2.                 suspensionForce = new Vector3(0f,suspensionForce.y,0f);
    Although it works , it also prevents it from completely sliding no matter how positioned the car on a slope.
    I would like a solution where a car wouldn't slide sideways on a slope unless the tires are positioned properly.

    I can code but I lack in the physics area , I'd go as far to say that I don't really know what should I really target in the wheels script , could it be the slipping angle or suspension force or some force I don't know about causing this?

    Thank you all for your time.
     
    Last edited: Dec 27, 2015
  2. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    Do you try play around with WheelCollider Sideways Friction -> stiffness values?
     
  3. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,430
    That's by design. The alternate physics model computes the tire forces based on the slip (= sliding velocity over the ground). It doesn't implement adherent friction.
     
  5. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
    Thanks Edy , I assume that means I should rewrite and make my own wheel raycast script with friction curves x_X
     
  6. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396
    No, as Edy's said, it's not about friction curves, tire physics is not that simple ;)
     
  7. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
    Teach me Sir *-*
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    read side velocity and apply counter force. it's not trivial enough for someone to bother teaching you how to solve what is a complex problem. You probably want to google how to get relative velocity first.
     
  9. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
    Okay , I will google it , thank you for the kind support. ^-^/
     
  10. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396
    It takes months/years for experienced studios to develop car physics that are more or less SIMILIAR to real car behaviour. So my advice - don't try to make realistic car behaviour, or buy ready solution from Edy is you really need something that can be called sim. Also no offence, but you shouldn't call your game sim if you are using "Unity's Car Tutorial alternate physics", as it has nothing to do with simulation ;)
     
    NoCakeNoCode likes this.
  11. NoCakeNoCode

    NoCakeNoCode

    Joined:
    Aug 27, 2015
    Posts:
    21
    You are totally right Roni , actually I'm not really planning to publish anything or the game as it lacks quality, I'm just learning it for fun and for the name its just temporary as I can't think of anything good but will do change it in the future to avoid the confusion. :)
     
  12. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,430
    Read tire velocity and apply counter force is a simple solution that works on most situations (Edy's Vehicle Physics is more or less based on that). But the tricky part is to calculate the adherent forces that are produced even when there's no effective sliding over the ground (i.e. slow turns without sliding or vehicle steady on slopes). This can be considered a physics challenge itself.