Hi
I know 3d has a point function.
With sprites, how can I figure out the angle to use with dbRotateSprite to make the sprite point towards a 2d coordinate.
I have made a function to do something similar based on the diffrence between the 2 X and Y coords:
void Rotate2Target(int Sprite, int Target)
{
int X = dbSpriteX(Sprite);
int Y = dbSpriteY(Sprite);
int TX = dbSpriteX(Target);
int TY = dbSpriteY(Target);
int DX = TX - X;
int DY = TY - Y;
if (DX < 0) DX = -1*DX;
if (DY < 0) DY = -1*DY;
if ((TX < X) && (TY == Y)) dbRotateSprite(Sprite,270);
if ((TX == X) && (TY < Y)) dbRotateSprite(Sprite,0);
if ((TX > X) && (TY == Y)) dbRotateSprite(Sprite,90);
if ((TX == X) && (TY > Y)) dbRotateSprite(Sprite,180);
if ((TX < X) && (TY < Y))
{
dbRotateSprite(Sprite,315);
if (DX > DY) dbRotateSprite(Sprite,292.5);
if (DY > DX) dbRotateSprite(Sprite,337.5);
}
if ((TX > X) && (TY < Y))
{
dbRotateSprite(Sprite,45);
if (DX > DY) dbRotateSprite(Sprite,67.5);
if (DY > DX) dbRotateSprite(Sprite,22.5);
}
if ((TX > X) && (TY > Y))
{
dbRotateSprite(Sprite,135);
if (DX > DY) dbRotateSprite(Sprite,112.5);
if (DY > DX) dbRotateSprite(Sprite,157.5);
}
if ((TX < X) && (TY > Y))
{
dbRotateSprite(Sprite,225);
if (DX > DY) dbRotateSprite(Sprite,247.5);
if (DY > DX) dbRotateSprite(Sprite,202.5);
}
}
This works, but is not perfect since it only covers 16 angles. So what would be a more accurate way to rotate a sprite to a XY coord?
Thank you