Hello all, im finishing up some shooter game. But i have got a slight problem with my shooting mechanism. the first 5 degrees go perfectly fine, but after that it goes off.
This is the method im using to shoot bullets:
public void shootBullets() {
float lengDir = 1;
switch (Ships.currentship) {
case Ships.NORMALSHIP:
lengDir = 15;
break;
}
float tempX = Player.getPlayer().getShip().getImageOriginX();
float tempY = -Player.getPlayer().getShip().getImageOriginY();
tempX += (Math.sin(java.lang.Math.toRadians(this.dir)) * lengDir);
tempY += (Math.cos(java.lang.Math.toRadians(this.dir)) * lengDir);
System.out.println(tempX + " , " + tempY);
Player.getPlayer().getBullets().add(new NormalBullet(x + tempX, y + tempY, dir));
}
lengdir is the length to the loop from the origin of the image. Im using 15 in this code.
Im using slick, so the point (0,0) is at the left top of an image.
getImageOriginX:
public float getImageOriginX() {
return image.getWidth() / 2;
}
The weapon is an object which is attached to the player. meaning that the x of the weapon is the x of the player (its basically a suit), same goes for the direction and the y position
output, starting facing north, and turning 90 degrees before shooting:
15.0 , -1.0
29.984562 , -16.680374
14.424611 , -30.98896
0.007386695 , -15.529313