Modelling Tank Velocity
Hi guys. I've started working on a 3D tank game in OpenGL and I need some advice on how to model the speed and direction of the tank based on the speed of it's two tracks.
This is a C++ project and I'm fairly confident with vector math and trig. The tank's left and right tracks can be controlled independently (ie. accelerated or even reversed). When both tracks are engaged are full speed, the tank should move forward. If the left track is spinning faster than the right track, the tank should move forward while turning to the right. Likewise, if the left track is reversed and the right track is at full speed, the tank should turn on the spot towards the left. Just like a real tank
I need some advice on how to model this. Each track has it's own speed and the tank itself has a position and a direction vector.
One idea  give each track a vector facing away from the tank's center position (ie. left and right) and increase the length as that track accelerates. Then build the direction vector from the sum of the two?
I'm sure this sort of thing has been done before
This is a C++ project and I'm fairly confident with vector math and trig. The tank's left and right tracks can be controlled independently (ie. accelerated or even reversed). When both tracks are engaged are full speed, the tank should move forward. If the left track is spinning faster than the right track, the tank should move forward while turning to the right. Likewise, if the left track is reversed and the right track is at full speed, the tank should turn on the spot towards the left. Just like a real tank
I need some advice on how to model this. Each track has it's own speed and the tank itself has a position and a direction vector.
One idea  give each track a vector facing away from the tank's center position (ie. left and right) and increase the length as that track accelerates. Then build the direction vector from the sum of the two?
I'm sure this sort of thing has been done before
Ugh... this sounds like a tough one to get right, because as the difference between the two track speeds changes the centre of rotation changes. i.e. if the left track has speed 1 and the right track has speed +1 it rotates about the very centre of the two. But if left = +1 and right = 0 it rotates about the centre of the right track.
I don't have any idea how to help you. Just wanted to make life more difficult for anyone that wants to try.
I don't have any idea how to help you. Just wanted to make life more difficult for anyone that wants to try.
You can think of the treads as 2 vectors on either side of the center of the tank, and connected by a bar at the middle. For example, in ASCII it would look something like this:
To calculate the total forward motion, you add the vectors of the 2 tracks. To calculate the rotation, you need to do the torque on the bar in the center. The bar is the simplest to calculate, but a box would probably be more correct for angular momentum. Of course, you could also just scale it as necessary, since game physics are all about approximations.
Code:
 
_
 
 
If I were modeling it, I'd probably fudge the physics a little bit.
So you have the two treads, and the speed for each can be any value between a min and a max (say 1 and +1.) At rest, these values are 0. +1 is full speed ahead, and 1 is full reverse.
The tank itself has its speed and orientation. For the speed (along the orientation) just sum the values of the two vectors. (You could also have a tank speed variable somewhere you could multiply by.) Example:
Tank speed = 10.0
Both treads forward: (1 + 1) * 10.0 = 20.0
One tread forward, one back: (1 + 1) * 10.0 = 0
Both treads back: (1 + 1) * 10.0 = 20.0
For orientation, I would take the difference between those two values, and again, multiply by some turn speed.
Tank turn speed = 5.0
So both treads equal: (x  x) * 5.0 = 0
Left tread forward, right back: (1  (1)) * 5.0 = 10.0 (positive = right turn)
Right tread forward, left back: (1  1) * 5.0 = 10.0 (negative = left turn)
Right tread forward, left at rest: (1  0) * 5.0 = 5.0 (slight left turn)
That gives you an angular velocity which you can apply to your orientation.
So you have the two treads, and the speed for each can be any value between a min and a max (say 1 and +1.) At rest, these values are 0. +1 is full speed ahead, and 1 is full reverse.
The tank itself has its speed and orientation. For the speed (along the orientation) just sum the values of the two vectors. (You could also have a tank speed variable somewhere you could multiply by.) Example:
Tank speed = 10.0
Both treads forward: (1 + 1) * 10.0 = 20.0
One tread forward, one back: (1 + 1) * 10.0 = 0
Both treads back: (1 + 1) * 10.0 = 20.0
For orientation, I would take the difference between those two values, and again, multiply by some turn speed.
Tank turn speed = 5.0
So both treads equal: (x  x) * 5.0 = 0
Left tread forward, right back: (1  (1)) * 5.0 = 10.0 (positive = right turn)
Right tread forward, left back: (1  1) * 5.0 = 10.0 (negative = left turn)
Right tread forward, left at rest: (1  0) * 5.0 = 5.0 (slight left turn)
That gives you an angular velocity which you can apply to your orientation.
Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man."  Alexander Seropian
Thankyou very much for your help guys! I'll try out these ideas and I'll let you know how I get on.
JustinFic  I tried out your idea and with a little tweaking it works great! Thanks.
At some point I may need to implement real torque rotation but for now this works and looks fine.
At some point I may need to implement real torque rotation but for now this works and looks fine.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Suggestions for controls in a tank driving game  iamflimflam1  0  2,603 
Oct 7, 2010 03:33 AM Last Post: iamflimflam1 

OpenGL Velocity and Grouping of Lines (C++, Xcode)  TheThirdL3g  2  4,965 
Jul 29, 2010 01:28 PM Last Post: SethWillits 

Combining then splitting angular and linear velocity  reubert  4  6,735 
Sep 5, 2006 12:47 AM Last Post: reubert 

Speed distance velocity and other headaches  Thinker  6  5,352 
Jul 3, 2003 09:55 AM Last Post: Thinker 

Getting XY speed from an angle/velocity  macboy  14  18,488 
Apr 19, 2003 01:32 PM Last Post: OneSadCookie 