I'm have a problem making an object face the mouse and the websites tutorials don't help!
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
rotate(a);
image(gun, width/2, height/2, 40, 40);
}
The object is rotating but it is rotating on 0, 0
So if you want the object to rotate on the center of the screen then,
function draw() {
background(0, backgroundColor2, 0);
cursor('crosshair.png')
frameRate(1000);
angleMode(DEGREES);
imageMode(CORNER)
let a = atan2(mouseY - height / 2, mouseX - width / 2);
translate(width/2, height/2);
rotate(a);
image(gun, 0, 0, 40, 40);
}
Here is a link for you to understand better https://www.youtube.com/watch?v=o9sgjuh-CBM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With