I have been working on a prototype game with tanks. I'm currently working on getting the motion of the tank working correctly. At the moment, the forward and reverse movement is working (reasonably well) using basic vehicle physics with 4 wheel colliders, but one of the features of a tank is that it can "turn on the spot" by rotating its "treads" in opposite directions. This is where I am having trouble.
My initial attempt was to apply a motor torque on the left wheels in the opposite direction as the right wheels but apparently, the forces just cancel eachother out and the tank doesn't move.
I've also tried to apply a angular torque to the tank's main body's rigid body, but the tank doesn't seem to rotate smoothly (I suppose it has something to do with the wheel colliders preventing the tank from moving sideways?)
Another option might be (but I havn't tried this) to just rotate the tank's transform directly. I wan't to avoid this because as far as I know, this doesn't play nicley with the physics engine. Perhaps it works if the tank is sitting on a flat surface, but if it's on rough terrain, I might run into some problems.
What I also want to try is to turn the WheelColliders 90 degrees (so front wheels turn +90 degrees and the back wheels turn -90 degrees) and apply a motor torque to get the tank to turn on the spot.
If anybody has any suggestions as to how I can get a vehicle to "turn on the spot", I'd love to hear it!
Thanks in Advance!
I've done this using the technique that you described (although with more wheels - 8 on each side).
You might find that if the sideways friction of the wheels is preventing the vehicle from rotating, you could actually angle the wheels to point in the direction of the rotation, so that they don't get dragged sideways.
Because the wheelcolliders are invisible, you wouldn't have to see this 'fake' wheel turning.
(Engage ASCII diagram mode!)
answered Feb 16 '10 at 12:19 PM
Hey, I'm working on the same but not working. Can you share your codes? Thanks!
answered Dec 29 '10 at 01:01 AM
you should turn left and right wheel colliders 90 and -90 and then accelerate. if wheel colliders are not good for your needs use sphere collider and rigidbodies and configurable joints.
answered Feb 16 '10 at 11:47 AM