I'm trying to implement a simple AI system in my DirectX Application. I'm trying to get my Ai to rotate and face the direction I want it to face towards, which I manage to do, but can't figure out how to get it to determine how to rotate to the given direction (i.e should it rotate left or rotate right?).
Here is the code I've got which works out the angle it needs to rotate by to face the direction it's given:
D3DXVECTOR3 incident = destination - position; float top = D3DXVec3Dot(&incident, &forwardVec); float bottom = sqrt((incident.x * incident.x) + (incident.y * incident.y) + (incident.z * incident.z)) * sqrt((forwardVec.x * forwardVec.x) + (forwardVec.y * forwardVec.y) + (forwardVec.z * forwardVec.z)); float remainingAngle = acos(top/bottom) * 180.0f / PI; The forwardVec is a D3DXVECTOR3 of which way the AI is currently facing.
acos(x), use 4 quadrantatan2(y,x). Not sure how to get yourx,ythough for you.