- Home /
vehicle speed limit not working
hi huys i am making a truck game and try to limit speed but it is not working. some how code works perfectly in my other projects.
if(rigidbody.velocity.magnitude < 5){
for(var i : int; i<powerWheels.length; i++){
powerWheels[i].motorTorque = motorMax * motor * vites;
}
}
here is my code. i tried magnitude or sqrmagnitude anr result is always same. trucks getting faster and faster.
It looks like you're applying brakes if the magnitude of the velocity is small.
no it does not mean anything. i remove that part and same result.
Then I'd suggest adding some logging. How many powerwheels does it have? What are the values of the variables you're using to set the value of motorTorque? And so on.
i tried 2,4 does it matter i also use it with normal way, without for but result is same.
my motortorque is 60.
Answer by akguldeniz · Feb 02, 2015 at 10:04 AM
solved it. motor torque stays if you wont give a new value.
correct code is
if(rigidbody.velocity.magnitude < 5){
for(var i : int; i<powerWheels.length; i++){
powerWheels[i].motorTorque = motorMax * motor * vites;
}
}else{
powerWheels[i].motorTorque = 0;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613181748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enter Vehicle Script not working! 1 Answer
How can I set up a tank steering mechanism? 2 Answers
Car turorial reset vehicle 2 Answers
Vehicle - terrain collision design 1 Answer