NPC stops in certain radius

master
Jonathan Hager 5 years ago
parent ee6c8738a2
commit f0f3ec986f

@ -57,7 +57,6 @@ public class MovingNpc extends Actor{
POI = new Vector2(area.getX() + ((float) Math.random() * (float) area.getWidth()), area.getY() + ((float) Math.random() * (float) area.getHeight()));
}
Vector2 movement = new Vector2(speed,0);
//movement.setAngleRad((float)Math.atan((double)(POI.y-getY())/(double)(POI.x-getX())));
movement.setAngleRad(StaticMath.calculateAngle(getX(), getY(), POI.x, POI.y));
if(movement.angleDeg() < 135 && movement.angleDeg() >= 45) {
@ -73,12 +72,17 @@ public class MovingNpc extends Actor{
facing = 3;
}
System.out.println(movement.angleDeg());
System.out.println(POI.x + " " + POI.y);
System.out.println();
movementX = movement.x;
movementY = movement.y;
if(StaticMath.calculateDistance(getX(), getY(), POI.x, POI.y, movement.angleRad()) < 10f) {
movementX = 0;
movementY = 0;
}
else {
movementX = movement.x;
movementY = movement.y;
}
if(movementX == 0 && movementY == 0){
}
else if(movementX == 0 && movementY != 0){
setY(getY()+movementY);

@ -42,11 +42,11 @@ public class StaticMath {
return (float) alpha;
}
public static double calculateDistance(int xPos1, int yPos1, int xPos2, int yPos2, double angle){
public static float calculateDistance(float xPos1, float yPos1, float xPos2, float yPos2, float angle){
float deltaX = xPos2 - xPos1;
float deltaY = yPos2 - yPos1;
double distance = Math.abs((deltaY / Math.sin(angle)));
return distance;
return (float) distance;
}
}

Loading…
Cancel
Save