Hello JGO, for the past few days I've been working on a new project.

Happy to say that the fancy side of the project is done, added a animated background, loading screen, audio, lighting etc.
Now I'm at the point where I've implemented a 'Game Screen', at the moment it's just a moveable player, a 'Gun' that rotates towards the mouse:
(Can't see it in this picture, but there is a 'Sights Cursor' for aiming present)

At the moment, when the mouse is pressed I am adding a 'Projectile' to a LinkedList<Projectile> like so:
1 2 3 4 5 6 7 8
| final int centerX = absX + width / 2; final int centerY = absY + height /2; final Projectile t = new Projectile(centerX, centerY); final double angle = Math.atan2(centerY - mX, centerX - mY); t.setAngle(angle); t.setVelX(8.0); t.setVelY(8.0); projectiles.add(t); |
Final code Snippet is from the Projectile class, this method is polled in the Game Loop:
1 2 3 4 5 6 7 8
| public void tick() { theta = Math.toRadians(angle); nextX = x + (velX * PROJETILE_SPEED) * -Math.cos(theta + Math.PI / 2); nextY = y + (velY * PROJETILE_SPEED) * -Math.sin(theta + Math.PI / 2); x = nextX; y = nextY; }
|
The Issue that I'm having is:
After I set the Projectiles angle (Calculated off of the mouse's coordinates), if I proceed to move the mouse while the projectile's in motion, it Override's the first angle I set for that projectile?
Notes:
I've tried in the 'tick()' method only initializing the 'theta' once, that didn't work, it still resets the final angle to where the mouse currently is.
Hope somebody can help me, I'm not too familiar with radians etc, the issue seems to be 'constantly updating the angle'.