Ask coding questions

← Back to all posts
How can I get the gun to rotate around the circle based on mouse position
BobTheTomatoPie (3356)

This is something I have always wondered but haven't been able to figure out in p5.js. here is a repetition of the question: How can I get the gun to rotate around the circle based on mouse position

Comments
hotnewtop
Coder100 (16903)
translate(X, Y);
rotate(ANGLE);
rect(-WIDTH / 2, 0, WIDTH, HEIGHT);

or something like that, play around with the values.

They should be with respect to 0, 0.

Why does this work? The thing is, rotate rotates based on the point (0, 0), so if you translate that to your position, rotate works fine.