Making a shape face the mouse

In this sketch, I have two ellipses that look like a fish. It follows the position of the invisible cursor. Along with moving as it currently is, I want to make the fish face the cursor at all times which means if i move the cursor up, the fish faces and moves up like a real fish in water would. Always swimming forward. I hope you can help me with this.

function setup() {
    createCanvas(600, 600);
  noCursor();
}

function draw() {
    background(255);
  
  
    noStroke();
    fill(random(0,0,0), random(105,105,105));
  ellipse(mouseX+14,mouseY,10,12);
  fill(random(0,0,0),random(105,105,105));
  ellipse(mouseX,mouseY,25,15)
     
}

1 Like

I think look at atan2

2 Likes

I will have a look at that :slight_smile: Thank you.

It worked!! Thank you very much :)))))

2 Likes