I'm trying to make an object face another object and this code looks like it should work but the objects face a completely different direction.
I have a function that sends the model number of the object im trying to rotate, and the object im trying to rotate it towards:
void Sentinal_Bullet::FaceTarget( int From_Obj, int To_Obj )
{
float Ax = dbObjectPositionX(From_Obj);
float Bx = dbObjectPositionX(To_Obj);
float Ay = dbObjectPositionY(To_Obj);
float By = dbObjectPositionY(From_Obj);
float angx = (float)atan2(Bx, Ax);
angx = angx * 180 / PI;
if (angx < 0)
{
angx = 360 + angx;
}
float angy = (float)atan2(By, Ay);
angy = angy * 180 / PI;
if (angy < 0)
{
angy = 360 + angx;
}
dbRotateObject(ObjNumber,angx,angy,0);
}
I'm not sure if I should be using X & Z or X & Y or Y & Z or what, maybe my equation is completely off, i'm not sure but they don't face the object, any suggestions?