MouseMoves: Following the Cursor

  • 30 favourites

Stats

7,689 visits, 11,177 views

Translations

This tutorial hasn't been translated.

Tools

Tracking to the cursor directly can be a great way to control sprites and maintains the precise movement of the mouse itself. But sometimes the movement of the mouse can be too quick and too sensitive, or simply too easy to use.

So instead of matching the position of the sprite directly to the mouse we will try to make it move towards where the mouse is positioned.

This can be done using these events:

This says that every tick the sprite will set its angle towards the position of the mouse X and Y coordinates and move forward at a speed of 2 pixels.

Hit the Run Layout button and test it out.

If you've noticed it moves very differently from the direct mapping. It moves at a constant pace almost like its crawling towards the mouse.

To change things up a bit we can use a different way of changing the angle. The Set Angle action makes the angle change instantly. Instead, we can make it change gradually by using the Rotate Towards Position action.

Now what it is doing is rotating at a rate of 3 degrees every tick towards where the mouse is positioned.

If you test it out you will notice it moves differently. It moves in a circular motion rather than just straight lines as before. This is because the angle doesn't aim towards the mouse instantly, but gradually turns to face it while still moving forward at 2 pixels every tick.

Various Ways to Use: Beginner

Follow the leader

This type of movement can be used to lead a sprite through a certain course like a maze.

Alternate player control

Moving directly to the mouse can be too easy. Make it more challenging by changing the way the sprite moves and how fast it moves.

Various Ways to Use: Advanced

Add acceleration

This tutorial showed only made the sprite move forward. By adding custom movement things like acceleration can be added to make more of a gravity effect. When I tried it a type of orbital effect was created with the sprite swinging around the mouse.

Most of the time, adding physics can make things more complicated since the behaviour is more difficult to predict.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!