# (wheel collider)Allow tank rotating while it doesn't move

Discussion in 'Physics' started by Ruslank100, Jan 15, 2020.

1. ### Ruslank100

Joined:
Apr 11, 2018
Posts:
13
Hello! I am creating a tank using wheel colliders, it moves forwards / backwards perfectly, but I have with troubles with making a one of the most important features of a tank - ability to rotate while not moving (here's a GIF that explains better what I do want to achieve):

The setup is pretty easy - just 4 wheel colliders(front left, front right, rear left, rear right). Here is my code that tries to steer the tank while not moving - it works somehow but the tank barely rotates.
Code (CSharp):
1. if (speed < 2)
2.                     {
3.                         switch (h)
4.                         {
5.                             case -1:
6.
7.                                 WheelColliders1[1].steerAngle = h * s.rotateAngle;
8.                                  WheelColliders1[3].steerAngle = h * s.rotateAngle;
9.                                 WheelColliders1[1].motorTorque = s.motor;
10.                                 WheelColliders1[3].motorTorque = s.motor;
11.                                 WheelColliders1[1].brakeTorque = 0;
12.                                 WheelColliders1[3].brakeTorque = 0;
13.                                 WheelColliders1[0].brakeTorque = s.brakeForce / 2f;
14.                                 WheelColliders1[2].brakeTorque = s.brakeForce / 2f;
15.
16.
17.                                 break;
18.
19.                             case 1:
20.
21.                                 WheelColliders1[0].steerAngle = h * s.rotateAngle;
22.                                 WheelColliders1[2].steerAngle = h * s.rotateAngle;
23.                                 WheelColliders1[0].motorTorque = s.motor;
24.                                 WheelColliders1[2].motorTorque = s.motor;
25.                                 WheelColliders1[0].brakeTorque = 0;
26.                                 WheelColliders1[2].brakeTorque = 0;
27.                                 WheelColliders1[1].brakeTorque = s.brakeForce / 2f;
28.                                 WheelColliders1[3].brakeTorque = s.brakeForce / 2f;
29.
30.
31.                                 break;
32.
33.                             default:
34.
35.                                 WheelColliders1[0].steerAngle = 0;
36.                                 WheelColliders1[1].steerAngle = 0;
37.                                 WheelColliders1[2].steerAngle = 0;
38.                                 WheelColliders1[3].steerAngle = 0;
39.                                 break;
40.                         }
41.                     }
Wheel indexes in my array(wheelColliders1) : 0 - front left, 1 - front right, 2 - rear left, 3 - rear right.
Thanks in advance for any help!

2. ### Edy

Joined:
Jun 3, 2010
Posts:
1,643
I have quite a few experience here...

What is shown in the GIF is simply applying torque to the wheels in one side while keeping the other side braked. No need to use steering, just forward and reverse torques.

A similar maneuver is rotating around the tank's vertical axis while keeping its position. That is called "neutral rotation". It involves applying forward torque to the wheels in one side and reverse torque to the wheels in the other side.

3. ### Ruslank100

Joined:
Apr 11, 2018
Posts:
13
I have modified the code a bit - so the tank rotates faster(but still too slow!) :
Code (CSharp):
1.
2.                 if (v == 0)
3.                 {
4.                     switch (h)
5.                     {
6.                         case -1:
7.                             WheelColliders1[0].motorTorque = -s.motor;
8.                             WheelColliders1[2].motorTorque = -s.motor;
9.                             WheelColliders1[0].brakeTorque = s.brakeForce;
10.                             WheelColliders1[2].brakeTorque = s.brakeForce;
11.
12.                             WheelColliders1[1].motorTorque = s.motor;
13.                             WheelColliders1[3].motorTorque = s.motor;
14.                             WheelColliders1[3].brakeTorque = 0;
15.                             WheelColliders1[1].brakeTorque = 0;
16.                             break;
17.                         case 1:
18.
19.
20.                             WheelColliders1[0].motorTorque = s.motor;
21.                             WheelColliders1[2].motorTorque = s.motor;
22.                             WheelColliders1[0].brakeTorque = 0;
23.                             WheelColliders1[2].brakeTorque = 0;
24.
25.                             WheelColliders1[1].motorTorque = -s.motor ;
26.                             WheelColliders1[3].motorTorque = -s.motor ;
27.                             WheelColliders1[1].brakeTorque = s.brakeForce;
28.                             WheelColliders1[3].brakeTorque = s.brakeForce;
29.                             break;
30.                         default:
31.
32.                             WheelColliders1[0].motorTorque = 0;
33.                             WheelColliders1[1].motorTorque = 0;
34.                             WheelColliders1[2].motorTorque = 0;
35.                             WheelColliders1[3].motorTorque = 0;
36.                             WheelColliders1[0].brakeTorque = s.brakeForce;
37.                             WheelColliders1[1].brakeTorque = s.brakeForce;
38.                             WheelColliders1[2].brakeTorque = s.brakeForce;
39.                             WheelColliders1[3].brakeTorque = s.brakeForce;
40.                             break;
41.                     }
42.                 }
43.
I am not sure - maybe something is wrong with the wheel colliders settings?
These are my settings :

unityunity