I have a game where there is a Player
and some enemies
. These enemies, just as the player itself, can shoot bullets
. But the angle
of bullets don't change as it is supposed to; The newly created bullet is supposed to find the angle between itself and the player, then just go in that direction - this has to be done in 360°
.
I have followed this answer but I believe that I have done something incorrect.
currently it only goes like this:
This is the part of code which takes care of X & Y of bullets:
angle = Math.atan2(Game.getPlayerY(), Game.getPlayerX()) - Math.atan2(getY(), getX());
if (angle < 0)
angle += 2 * Math.PI;
setX((getX()+(float)(Math.sin(angle)))-Config.BulletSpeed);
setY((getY()+(float)(Math.cos(angle)))-Config.BulletSpeed);
How do I make the Bullets
go in a certain angle?