I know you can use vector.heading()
to get the angle of direction. I have been using this in my code but it’s not working correctly.
class Boid {
constructor() {
this.loc = createVector();
this.vel = p5.Vector.random2D();
this.vel.setMag(random(1, 2));
this.acc = createVector();
this.maxSpeed = 1;
}
draw() {
stroke(255);
strokeWeight(2)
push();
beginShape();
rotate(this.vel.heading());
vertex(this.loc.x, this.loc.y);
vertex(this.loc.x - 3, this.loc.y + 10);
vertex(this.loc.x, this.loc.y + 8);
vertex(this.loc.x + 3, this.loc.y + 10);
endShape(CLOSE);
pop();
}
update() {
this.loc.add(this.vel);
this.vel.add(this.acc);
this.vel.limit(this.maxSpeed)
}
}
They appear to point in a random direction and not “point” toward their velocity vector. What am I doing wrong?