Hello! I'm not quite sure where this topic should go in the pre-university or university forums, but figured this would be the most appropriate place in the end, only because while I'm using the determinant of a matrix, you should get the same result if you rearranged and substituted to solve for simultaneous equations. Anyway, I'm trying to program an "aimbot" for a simple 2D game.
Here's the scenario.
You are riding around in a tank at position P. Your target is at point T, moving in a direction with speed .
Given that the speed of your projectile is , find the angle you should aim at such that if your projectile will hit the target if you were to fire now.
Here's a diagram to help illustrate:
In other words, find theta in terms of all the other variables.
Here's what I have so far:
The two vectors and are linearly dependent (by t), so the determinant of the matrix formed by and is 0.
Thus, expanding into components, I get
Gathering up all the theta components, I have:
I can then use the trigonometric identity,
So if I let and , then I get the following hideous expression:
So as a final expression,
This looks correct, but when I coded it up, it only seemed to work if the target lay within the first quadrant.
Does anyone have any ideas on how to get around this without having to deal with things on a quadrant-by-quadrant basis?