Math, angles, atan2 etc?
Is anyone in here fairly proficient in these aspects? Apparently, I'm a noob, and can't quite get things to work.
It's a bit embarrassing, but here we go:
First of all, think 2D.
I have a missile being launched, headed for a specific target.
The missile has typical attributes like x, y, acceleration, speed, turning-speed etc.
More importantly, it has a Direction (- PI to PI) and a similar DirectionToTarget (-PI to PI).
These directions are in radians, as you know by now, after using the atan2-formula on DX,DY.
Now, in my limited understanding, I thought I could simply DECREASE the Direction if Direction was GREATER than DirectionToTarget, and if it SMALLER, I would simply INCREASE it. And in some cases, this will work. However, in some cases, my missile will rather turn 265 degrees left, in stead of 95 degrees to the right...
So I thought, ok, we need to cater for the 4 different "quadrants" that are possible here, but I have not been able to get this stuff right.....
Can anyone tell me how I can alter my missiles direction "in the right direction" towards the "direction to the target" and have it pick the shorter way around every time?
Any takers?
__________________
- Spinner
Original creator of Planetarion, ManagerLeague and AD2460.
|