I’ve been making an arras.io (a top down shooter) type game, and I’m trying to make the player (which is in the centre)'s cannon(s) face the cursor, using atan2()
and the rotate()
function. It does work as expected, but sometimes the cannon just freezes and doesn’t move at all, sometimes resolving itself and continuing as normal, or just staying there. This is mostly random and I don’t have a clue as to what causes it.
void setup() {
fullScreen();
}
void draw() {
fullScreen();
pushMatrix();
strokeWeight(5);
translate(width/2, height/2);
render(atan2((mouseY - height / 2), (mouseX - width / 2)));
popMatrix();
}
void render(float _rot) {
pushMatrix();
rotate(_rot);
fill(160);
stroke(lerpColor(160, color(0), 0.1));
beginShape();
vertex(0, -5);
vertex(20, -5);
vertex(20, 5);
vertex(0, 5);
endShape(CLOSE);
popMatrix();
}
I’m making this sketch in OpenProcessing. I know that mouseX and mouseY don’t update when the cursor is off the window, but when this happens the mouse has been in the window the whole time the sketch was being run.
Is this just a Processing thing? Or is this possible to fix? Please let me know.