Answer the question
In order to leave comments, you need to log in
2D movement not working?
private double GetAngle(double x1,double y1,double x2,double y2)
{
double ang = Math.Atan((x1 - x2) / (y1 - y2)) * Rad2Deg;
if ((x1 < x2) && (y1 > y2))
return ang;
else if (((x1 < x2) && (y1 < y2)) || ((x1 > x2) && (y1 < y2)))
return ang + 180d;
else
return ang + 360d;
}
public void MoveTo(double x, double y)
{
TX = x; TY = y;
Angle = GetAngle(TX, TY, X, Y);
TimerMove.Interval = 10;
TimerMove.Start();
}
private void Move(object sender, EventArgs e)
{
X += Speed * (Math.Sin(Angle * Rad2Deg));
Y += Speed * (Math.Cos(Angle * Rad2Deg));
}
Answer the question
In order to leave comments, you need to log in
If the Rad2Deg constant is defined as 180/pi, then in the Move function it is necessary not to multiply by it, but to divide.
And in general, it would be nice to at least briefly describe what you want to get and what you get.
Chet tells me that you do not have a mainloop, where it all works, or it is, but the functions are not called there. Do you have mainloop("the main loop where all changes are processed")?
TimerMove.Interval = 10;
TimerMove.Start();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question