Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Vehicle Controller accelerating with no input

Discussion in 'Physics' started by xorpheous, Oct 11, 2018.

  1. xorpheous


    Mar 28, 2018
    I'm having an issue with the Standard Assets Vehicle Controller providing an acceleration to the car when there is no input. To be sure that the Horizontal and Vertical axes are zero, I created a display for their values, I also checked the value of the thrustTorque and -m_ReverseTorque*footbrake to be sure that the axes values were being passed and handled correctly. When there is no keyboard input, all of these values are zero as they should be.

    When I first start the game, the car sits stationary as it should. I can roll forward a bit and allow the car to coast to a stop, and it sits stationary just fine. If I use the brake ("S" or "Down Arrow") then the car will slowly begin to accelerate backwards. For example, if the car is moving forward and I use the brake to slow down and release the key while the car is still rolling forward, its forward velocity will continue to drop until the car stops and then begins to accelerate backwards. Pressing the accelerator ("W" or "Up Arrow") now produces insufficient torque to halt the rearward motion. I've included the settings for my front wheel colliders and the CarController script.

    Any insight would be very welcome at this point. Something about the controller is failing to reset to zero when all input is released, but I can't locate what it is that's driving this erroneous motion.

  2. xorpheous


    Mar 28, 2018
    I got it sorted. ...and yes, I know now that I was completely misunderstanding the nature of the Extremum/Asymptote Slip/Value parameters. Got that straight, but that wasn't the issue. The issue was with the
    method in the CarController.cs script. Even though FWD was selected and no motorTorque should have been applied to
    , there must have been some residual creeping in somewhere. I'm still not sure how torque was being applied to the rear wheels, but in the case for FWD cars, I explicitly set the torque to zero and that worked a treat.

    Code (CSharp):
    1.  case CarDriveType.FrontWheelDrive:
    2. thrustTorque = accel * (m_CurrentTorque / 2f);
    3.                     m_WheelColliders[0].motorTorque = m_WheelColliders[1].motorTorque = thrustTorque;
    4.                     m_WheelColliders[2].motorTorque = m_WheelColliders[3].motorTorque = 0.0f;  // <-- I inserted this line.
    5.                     break;
    I'd still like to know where the torque for the rear wheels was being set, because this isn't really a fix to the code. It's just a convenient workaround.