Hey JGO, I’m trying to figure out how to go about firing a projectile from my players position to the coordinates that were tagged when the fire button is pressed.
(Game is static tiles for now, no movement)
I’m not sure about how I should do this so I’m coming here asking for help as I don’t have that much experience with angles/vectors.
I think I’ll be able to figure out the collision, I just need help with the actual logic for moving at an angle
When fire button is clicked:
public static void update() {
// firing button is down
if (leftClickDown){
// TODO: Implement delay system.
final int velocity = 5;
bullets.add(new Bullet(playerX, playerY, mouseX, mouseY, velocity));
}
// update every bullet. (Move)
for (Bullet b : bullets) {
b.update();
}
}
Bullet class:
package org.game.core.player;
public class Bullet {
// actual position of bullet.
private int x, y;
// the destination of the bullet.
private int destinationX, destinationY;
// handles x/y velocity
private int velocity;
public Bullet(int x, int y, int destX, int destY, int velocity) {
this.velocity = velocity;
this.x = x;
this.y = y;
destinationX = destX;
destinationY = destY;
}
public void update() {
// HERE IS WHAT I NEED TO IMPLEMENT.
}
}
Thanks for any help/feedback