- Home /
Max vehicle velocity using "Vehicle Tools"
Hello,
I´m trying to use the Vehicle Tools asset (this one: https://assetstore.unity.com/packages/essentials/tutorial-projects/vehicle-tools-83660). I´m trying to set up the code so the vehicle has a max velocity. I have tried this:
if (rgb.velocity.magnitude < MaxVel)
{
if (wheel.transform.localPosition.z < 0 && driveType != DriveType.FrontWheelDrive)
{
wheel.motorTorque = torque;
}
if (wheel.transform.localPosition.z >= 0 && driveType != DriveType.RearWheelDrive)
{
wheel.motorTorque = torque;
}
}
But it doesn´t seem to work as the vehicle will continue accelerating.
Does someone has any idea of how to do this?
Thank you guys!
Your code either does nothing, or sets the wheel torque to the variable torque.
You probably want an "else" statement somewhere that sets the torque to 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220612215738im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Added force to rigid body, but wont move same speed as horizontal speed... if rotating 1 Answer
How would you code a Wind script? 1 Answer
Physics goes crazy when rigidbody collides with moving character controller 0 Answers
Using rigidbody.AddForce and speeding the object 2 Answers
RigidBody Question 1 Answer