In the game im making I want to use the mouse cursor to aim with. This is the code I have for know to make the bullet move towards the mouse cursor:
Locating the mouse position private PointerInfo mouse = MouseInfo.getPointerInfo(); private Point point = new Point(mouse.getLocation()); Making the bullet kinda move towards the mouse cursor
if(point.getX() > player.getX()){
setX(getX() + 1);
}
if(point.getX() < player.getX()){
setX(getX() - 1);
}
if(point.getY() > player.getY()){
setY(getY() + 1);
}
if(point.getY() < player.getY()){
setY(getY() - 1);
}
The problem is that the bullet won't travel precisly to the mouse cursor but travel in a 45 degree path dow to the left if the mouse cursor is somewhere in that area, the same thing goes for up to the left, down to the right and up to the right.