or “Can I Interpret Angular Movement as Linear Velocity” or “How I learned to stop worrying and love Mathematics”.
Hi again, Unity Answers fellas.
I’m currently trying to simulate a modern battle tank’s Fire Control System in Unity. Here’s a summary of what I have so far:
- The sight is pointed at a target (aimpoint)
- A laser (raycast) is shot out to get the range
- The aimpoint is adjusted upwards depending on distance, muzzle velocity, and tank tilt
- Lead is added depending on the tank’s current velocity as well as the target’s
- The turret slews around and elevates the gun to center on the final aimpoint
- The shot is fired and hits the target. On the way!
As it stands, it’s already pretty good. Hitting a moving target (while moving yourself) at less than a 1000m is a cakewalk while doing the same thing at 3000+ meters might make you sweat a little bit. But I want to make it better. Turn your attention to number 4.
“Lead is added depending on the tank’s current velocity as well as the target’s”
This literally means I get the velocity of the rigidbody attached to the target and do my calculations from there. It works fine and dandy if the Gunner is an NPC who can store a reference to the bad guy in his scripts somewhere and just take a peek at his velocity now and then. But what if the Gunner is the player?
Here’s a shot of my totally-WIP Gunner’s Primary Sight Extension. The red numbers below the crosshairs are the range to the target. The light gray cross is the mouse cursor.
The GPSE, as a turret, isn’t controlled using the traditional Mouse Look. Instead, the distance between the cursor and the center of the screen is calculated and the view rotates accordingly. If any of you have played M1 Tank Platoon 2 (I have) or Steel Beasts (I haven’t), you’d know that the lead is actually calculated from the rotation speed of the viewport and the distance to the target. Hence, once you are able to keep a moving target in the center of the screen, the turret will automatically add lead, ensuring a hit (unless the target suddenly changes direction while the shell is in flight).
So here’s what I want to know:
“Can I conjure up a velocity value based on the movement of the center of the screen and taking into account the distance and magnification?”
or
“If I aim my camera at an imaginary point a specific distance away from me and pan the camera slowly, can I get that moving imaginary point’s velocity?”
