Search Unity

Car keep moving when wheel collider motor torque zero

Discussion in 'Physics' started by Xhitman, Aug 4, 2020.

  1. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Car still moving when motor = 0

    Code (CSharp):
    1. public void FixedUpdate()
    2.     {
    3.         foreach (AxleInfo axleInfo in axleInfos)
    4.         {
    5.             if (axleInfo.steering)
    6.             {
    7.                 axleInfo.leftWheel.steerAngle = steering;
    8.                 axleInfo.rightWheel.steerAngle = steering;
    9.             }
    10.             if (axleInfo.motor)
    11.             {
    12.                 axleInfo.leftWheel.motorTorque = motor;
    13.                 axleInfo.rightWheel.motorTorque = motor;
    14.  
    15.                
    16.             }
    17.            
    18.             if(motor==0)
    19.             {
    20.                 axleInfo.leftWheelAnimator.speed = 0;
    21.                 axleInfo.rightWheelAnimator.speed = 0;              
    22.             }
    23.             else
    24.             {
    25.                 axleInfo.leftWheelAnimator.speed = 1;
    26.                 axleInfo.rightWheelAnimator.speed = 1;
    27.             }          
    28.         }
    29.     }  
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Can't see anything wrong...
     
  3. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    Shouldn't the tank stop moving in few secs when motortorque zero( track animation stop)? It keeps moving forever. I also find similar problem in the car sample scene, the car "slide" very long distance after motor torque become zero.
     
  4. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    452
    I think I solve the sliding problem by adding infinity brake torque. (very high brake torque do not work)

    But I find a new problem now, the acceleration is awful. Motor torque do not increase the tank velocity, and wheel rpm is read only. How can i accelerate it?

    Code (CSharp):
    1.  if (motor == 0)
    2.                 {
    3.                     axleInfo.leftWheel.brakeTorque = Mathf.Infinity;
    4.                     axleInfo.rightWheel.brakeTorque = Mathf.Infinity;
    5.                 }
    6.                 else
    7.                 {
    8.                     axleInfo.leftWheel.brakeTorque = 0;
    9.                     axleInfo.rightWheel.brakeTorque = 0;
    10.                 }