Wow, I feel bullied here. You two pounding at me without me even replying haha...
Yeah, sorry about that. We should have used softer gloves.
I second Paradigm Shifter's opinion about drawing diagrams and fixing your understanding when there are unexpected results, instead of just tweaking the code until it seems to work. I feel very strongly about this, because I used to just tweak the code until it seemed to work, and that got me in trouble later on.
Yeah I get that. I really do want to know whats happening but in this particular case I just need this to work, and I'm happy. I'm pretty sure I can learn every row of logic when it's up and working... And I really wanna do this one without Matrices and such...
I have tweaked the code a bit now after reading previous posts but I still get very shady results. The spawn of the bullets seem to follow a much larger radius than the ship.
Code for rotating player towards direction (now with Math.Atan2(Y,X) instead of XY and no alter to the rotation with Math.PI:
theta = Math.atan2(
shootingPad.getKnobY() - shootingPad.getHeight() / 2, shootingPad.getKnobX() - shootingPad.getWidth() / 2);
rotation = (float)Math.toDegrees(theta);
But it seems like it's still here the spawn position gets really screwed (still):
private void shoot(){
double angle = rotation;
float x2 = x;
float y2 = y;
gunRightTipX = getCenterX() + 48;
gunRightTipY = getCenterY() + 36;
float bulletX = x2 + gunRightTipX * (float)Math.cos(Math.toRadians(angle)) - gunRightTipY * (float)Math.sin(Math.toRadians(angle));
float bulletY = y2 + gunRightTipX * (float)Math.sin(Math.toRadians(angle)) + gunRightTipY * (float)Math.cos(Math.toRadians(angle));
Bullet b = new Bullet(new TextureRegion(Assets.bullet), bulletX, bulletY, (float)angle, 5f);
bulletList.add(b);
}
Am I referring to something crazy here?