- Home /
Implement a vehicle that can "turn on the spot".
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!
Answer by duck · Feb 16, 2010 at 12:19 PM
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!)
// when rotating: when driving straight:
//
// /####\ |####|
// #### ####
// #### ####
// ####/ |####|
Answer by Ashkan_gc · Feb 16, 2010 at 11:47 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.
Hello i am tryng to do that same thing but found i differnt salution.
i used 6 collides 3 for left and 3 for the right track
the wheel 4 wheel colliders at the front and back have high sidways slip, by lowering the extremuum value to 2000, so that they can be forced to move but are used to help motor the behocal and make it stable.
th two middle colliders have little sidways slip to stop the tank sliding on a hill to make up for the other collders having high slip. But because they are in the center and are perpendicular to the center of rotation they rotate fine. I only have one mass in my tank at the moment so was very simple and will need to be changed over time.
A problem i had is if the tank moves forward or backwords during rotation the problem got worse and it speeds off. Adding a ridigid body to the tank with some drag APPEARS to solve the issue, I have not fully tested it but it fits my needs atm.
hope this works for you or helps someone else.
Answer by Esteban · Dec 29, 2010 at 01:01 AM
Hey, I'm working on the same but not working. Can you share your codes? Thanks!
Your answer
Follow this Question
Related Questions
Fast motion of vehicle 0 Answers
Question about Wheel collider use 1 Answer
Getting contact force between two rigidbodies 1 Answer
AddExplosionForce 0 Answers
Car goes a bit left when moving 1 Answer