- Home /
How to turn a tank?
I have made a sript which allows u to drive a tank. I used the wheelcolliders and the motortorque, however I have a problem: I don't Know how to rotate it. I only know that if a tank wans to turn left or right he has to turn forward the wheels on the left, while turns back the wheels on the right. I have a problem however: it doesn't turn on his pivot axes, but it goes a little forward and backward. Please, help
var fwdDrive = Input.GetAxis("Vertical")*power;
var h = Input.GetAxis("Horizontal")*maxSteer;
for (var i = 0; i < 5; i++)
wheelColliders[i].motorTorque = h+fwdDrive;
for (i = 5; i < 10; i++)
wheelColliders[i].motorTorque = -h+fwdDrive;
obviously it's in the fixedupdate function
Answer by aldonaletto · Dec 12, 2011 at 09:16 PM
This code seems ok for me: you apply the common drive torque added to a differential torque to each side according to the steer control.
Compared to a car, a thank has low sideways friction relative to its huge mass. Maybe you should reduce the sidewaysFriction.stiffness to a low value, 0.2 or 0.3, to ease the tank rotation.
[1]: http://unity3d.com/support/documentation/ScriptReference/WheelFrictionCurve.html