I'm trying to spawn 3 arrows that are lined up with each other. I used some util code from someone else to make it work for north, south, east, and west. My problem is when I launch towards northeast, northwest, southeast, and southwest, where the arrows are not properly alligned. Code looks as following:
The getCardinalDirection looks like this:
Code:
String a = MathUtils.getCardinalDirection(player);
Arrow volleyArrowOne = arrow.getWorld().spawnArrow(event.getProjectile().getLocation().clone(), arrow.getVelocity(), 2f, 0f);
Arrow volleyArrowTwo = null;
Arrow volleyArrowThree = null;
if (a == "E" || a == "W" ) {
volleyArrowTwo = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().add(1, 0, 0), event.getProjectile().getVelocity(), (float) 2, (float) 2);
volleyArrowThree = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().subtract(1, 0, 0), event.getProjectile().getVelocity(), (float) 2, (float) 2);
} else if (a == "N" || a == "S") {
volleyArrowTwo = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().add(0, 0, 1), event.getProjectile().getVelocity(), (float) 2, (float) 2);
volleyArrowThree = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().subtract(0, 0, 1), event.getProjectile().getVelocity(), (float) 2, (float) 2);
}
else if(a == "NE" || a == "SW") {
volleyArrowTwo = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().add(-0.5, 0, 0.5), event.getProjectile().getVelocity(), (float) 2, (float) 2);
volleyArrowThree = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().subtract(0.5, 0, 0.5), event.getProjectile().getVelocity(), (float) 2, (float) 2);
}
else if(a == "NW" || a == "SE") {
volleyArrowTwo = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().add(-0.5, 0, 0.5), event.getProjectile().getVelocity(), (float) 2, (float) 2);
volleyArrowThree = event.getProjectile().getWorld().spawnArrow(event.getProjectile().getLocation().clone().subtract(-0.5, 0, 0.5), event.getProjectile().getVelocity(), (float) 2, (float) 2);
}
volleyArrowOne.setShooter(player);
volleyArrowTwo.setShooter(player);
volleyArrowThree.setShooter(player);
Code:
public static String getCardinalDirection(Player player) {
double rotation = (player.getLocation().getYaw() - 90) % 360;
if (rotation < 0) {
rotation += 360.0;
}
if (0 <= rotation && rotation < 22.5) {
return "N";
} else if (22.5 <= rotation && rotation < 67.5) {
return "NE";
} else if (67.5 <= rotation && rotation < 112.5) {
return "E";
} else if (112.5 <= rotation && rotation < 157.5) {
return "SE";
} else if (157.5 <= rotation && rotation < 202.5) {
return "S";
} else if (202.5 <= rotation && rotation < 247.5) {
return "SW";
} else if (247.5 <= rotation && rotation < 292.5) {
return "W";
} else if (292.5 <= rotation && rotation < 337.5) {
return "NW";
} else if (337.5 <= rotation && rotation < 360.0) {
return "N";
} else {
return null;
}
}
