So I want a Spacecraft to move to a Target-Position, but it always goes far off the course.
Here's my Code, so if anyone has got an idea whats going wrong, please help me
public void moveToTarget(double targetX,double targetY)
{
//Position of the Craft
double craftX;
craftX = getX();
double craftY;
craftY = getY();
//Calculation of the Distance in X- and Y-Direction
double distX;
distX = targetX - craftX;
double distY;
distY = targetY - craftY;
//Distance between Craft and Target
double distTargetDouble;
distTargetDouble = Math.sqrt((distY * distY) + (distX * distX));
int distTarget = (int) distTargetDouble / 2;
//Calculation of Angle
double turnRadiusDouble;
turnRadiusDouble = Math.toDegrees(Math.atan(distY / distX));
int turnRadius = (int) turnRadiusDouble;
//Movement
//Turning
turn(turnRadius);
//Moving
int i=0;
while (i < distTarget) {
move(2);
i++;
}
}
