# Rectangle Follow (Using Mouse)

**URL:** <https://discourse.processing.org/t/rectangle-follow-using-mouse/4238>\
**Category:** Project Guidance\
**Created:** [October 8, 2018, 7:32am UTC](https://discourse.processing.org/t/rectangle-follow-using-mouse/4238 "2018-10-08T07:32:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Tex](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Daniel\_Tex](https://discourse.processing.org/u/Daniel_Tex)\
**Post date:** [October 8, 2018, 7:32am UTC](https://discourse.processing.org/t/rectangle-follow-using-mouse/4238/1 "2018-10-08T07:32:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 8, 2018, 8:12am UTC](https://discourse.processing.org/t/rectangle-follow-using-mouse/4238/2 "2018-10-08T08:12:27Z")

</div>

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()](https://processing.org/reference/PVector_angleBetween_.html) function. Finally you can rotate you rectangle by that angle with the [rotate()](https://processing.org/reference/rotate_.html) function.
