I'm doing a (probably simple) task, in which i want to make a drawed object move to a user-controlled (drawed too). All i have is the players X and Y coördinate, defined as respectively Xp and Yp. The object that has to move (after trigger, not included in code down here) to the 'player-object' has its coördinates defined in this.X and this.Y.
int xDirection = Xp - this.X;
int yDirection = Yp - this.Y;
int angleInDegrees = (int)Math.Atan2(xDirection, yDirection);
double radians = (Math.PI / 180) * angleInDegrees;
double xTmp = 3 * Math.Cos(radians);
int xSpeed = (int)xTmp;
double yTmp = 3 * Math.Sin(radians);
int ySpeed = (int)yTmp;
Console.WriteLine(xDirection);
Console.WriteLine(yDirection);
Console.WriteLine(xSpeed);
Console.WriteLine(ySpeed);
Console.ReadLine();
This doesn't give me the right figures, so i was wondering what may be wrong.
The toughest bit about this probably the fact that the object that has to move to the playerobject may be approached from all the sides (360 degrees) but there's no angle of approach available.
I hope to be complete with my question, Tim