Rectangle Follow (Using Mouse)

How would I make the rectangle look at the mouse but unable to move (Ex. such as the online browser game “diep.io”) thanks!

Hi Daniel_Tex,

First create a vector pointing to the right (1, 0) and another one fro the center of your retangle to your mouse position (mouseX - rectX, mouseY - rectY). Then get the angle between the 2 of them with the angleBetween() function. Finally you can rotate you rectangle by that angle with the rotate() function.

1 Like