I hate to admit it, but I am awfully stuck on a game I have only just bleeding started.
The concept is quite simple really, I have a triangle that I want to point to the mouses position. Naturally I use the atan2 function in p5.js as this is recommended for such tasks. I know I am calculating the amount to rotate wrong, I want it to rotate via the midpoint of the triangle but point the tip towards the mouse. If somebody could walk me through the maths behind this I would greatly appreciate it.
var player;
function setup() {
createCanvas(400, 400);
player = new Player();
}
function draw() {
background(0)
fill(255);
player.update();
}
function Player() {
this.pos = createVector(width/2, height/2);
this.r = 20;
this.direction = 0;
this.radians = 0;
this.update = function() {
push();
stroke(255);
noFill();
translate(this.pos.x, this.pos.y);
this.radians = atan2(mouseY-this.pos.y, mouseX-this.pos.x);
rotate(this.radians);
triangle(-this.r, this.r, this.r, this.r, 0, -this.r);
ellipse(0, 0, 20, 20);
pop();
}
}