# How can I set up a tank steering mechanism?

Here is the basic formula I want to use, (thank you mooserman352 @ gamedev.net)I am just not sure how to write it in JavaScript.

Let R be the radius of the circle, the distance from the turning point to the center of the tank. Let D be the distance from the center of the tank to each tread. Suppose you wait for some time T, so that the tank makes a nice complete circle around the turning point. The outer track has drawn out a circle of radius (R+D) and length 2*pi*(R+D), and the inner track a circle of radius 2*pi*(R-D). Since 2*pi*(R+D) = V1*T and 2*pi*(R-D) = V2*T, (R+D)/V1 = (R-D)/V2. Solving for R*(1/V1 - 1/V2) = D*(1/V1+1/V2). Seems reasonable, if v1 = v2, R=infinity; if v1 = -v2, R=0.

My previous attempts were either a total disaster, or more like normal car movement. Can anyone help me out with this? Thanks.

Scripting noob

To be honest, those formulas are making my eyes boggle slightly. I'm sure they're probably correct, but often in Unity you don't really need to do these kind of complex calculations yourself because you have a physics engine at your fingertips which can do it all for you.

There are a number of ways you can do tank-like movement:

• Simply use AddTorque to rotate your tank, combined with AddForce to push it backwards or forwards
• Use AddForceAtPosition to add a force at each side of the tank, relative to how fast each track is moving
• Use a row of wheel colliders along the base of each track, and apply motorTorque to them, to simulate the power of each track)

I recently used this 3rd method to simulate the tracks of an excavator, however I didn't tackle the 'driving in a circle' problem. In mine, you could simply drive forward, backward, or rotate on the spot. Of course, you could use free-rolling wheelcolliders combined with either of the first two methods, so that your tank rolls properly (and perhaps just apply brakeTorque when necessary), but you apply force to the body to get it moving.

Wee bit late of an answer, but...

It would seem that you could also use the UnitySteer classes to implement the forces. I would suggest creating a vehicle that has two different steering calculations, one for each track, and mix the forces depending on how much work each track is doing.