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

Dynamic and Static Friction

Discussion in 'Physics' started by Jymmy097, Nov 21, 2015.

  1. Jymmy097

    Jymmy097

    Joined:
    Jul 7, 2014
    Posts:
    67
    Hi everybody,

    I'm developing a game where a tank is moved by an engine mounted on it. The engine tells the rigidbody component to go forward by applying it an acceleration. I apply an acceleration and not a force because I wanted full control over the maximum velocity of the tank (I've also tried with a combination of force and drag, but it didn't help).

    Now I'm facing the friction problem:
    I want the tank to move to a maximum speed of Vmax in a certain kind of terrain (which I call normal terrain) and slower/faster on other kinds of terrains. Let's suppose for example that the normal terrain is the dirt and the other terrain is the sand. Of course the friction coefficients change. I'm interested in the coeff. of the normal terrain (which I call normal friction coeff.): I want to assign the tank a maximum velocity to be reached in a certain amount of time. So I wrote:
    Code (CSharp):
    1.     public float MaximumSpeed = 0;          //The maximum speed the engine can reach if mounted on a tank that weights 1.
    2.     public float ForceMagnitude = 0;        //Gives acceleration to the body and takes into account its mass
    3.  
    4. private float EngineAcceleration;
    5.     private float ActualMaxSpeed;
    6.  
    7. void Start()
    8.     {
    9.         _rigid = GetComponent<Rigidbody>();
    10.         EngineAcceleration = ForceMagnitude / _rigid.mass;
    11.         ActualMaxSpeed = MaximumSpeed / _rigid.mass;
    12.     }
    13.  
    The problem I'm facing is how to calculate the additional acceleration if I have to reach the same Vmax in the same time on a normal terrain.
    I also tried to write this:
    Code (CSharp):
    1.  
    2. Fdyn = _rigid.mass * 9.81f * dyn_drag_coeff
    3.  
    so that
    Code (CSharp):
    1.  
    2. dA = Fdyn / _rigid.mass = 9.81 * dyn_drag_coeff
    3.  
    But it does not work (the tank moves very slowly to the target velocity), so I experimented a bit and I found out that the friction force is not only calculated with the mass, the coefficient and the g constant, but also by taking into account the grounded area of the collider (I tested it by applying the same force to two cubes, one of which was 2 times bigger than the other and while the first one began to move - or roll - the other stayed still or very very slightly moved).

    So the question is: How can I take that area into account?
    PS: I'm currently using only box colliders.

    Thanks in advance.

    Jymmy097
     
  2. Jymmy097

    Jymmy097

    Joined:
    Jul 7, 2014
    Posts:
    67
    I've solved the problem:

    I switched back to the force approach. Then I noticed this line in the Unity manual I haven't noticed before:

    And now it works perfectly.

    Thanks.

    PS: Admins may delete the thread if they like.