Moving Character towards mouse

00george

  • Posts: 161
Hi Im trying to make my character move towards the mouse but he will only go diagonal. You can see by going to this link http://www.stencyl.com/game/play/11388. A picture of the behaviour is below.

Hectate

  • *
  • Posts: 4643
The block you're using sets motion based on a X direction and a Y direction relative to the actor. So for example, -10 Xdir and -10 Ydir would send the actor diagonally up and to the left.

The numbers you're putting in the field are the X and Y values of the mouse's position. Both will always be positive numbers and as a result, your actor is always travelling down and to the left.

Your solution will be to not use the X/Y of the mouse directly, but instead subtract the actor's X/Y position from the mouse's position. So, just put a "Number - Number" (the subtraction block) inside those two fields and in the first half put the X/Y of Self and then the second should be X/Y of mouse.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

00george

  • Posts: 161
Thank you so much. The problem is now he slides past where I want him to go.

coleislazy

  • *
  • Posts: 2607
That block simply gives the actor a direction and force. It will keep moving until something stops it. You can check the actors position then stop him using the set x-speed block (and y) to 0.

If you want it to slide to the mouse location, you can try using a tweening block, but they can be inaccurate and changes to its course can't be made until it reaches its destination.

00george

  • Posts: 161
Thank you almighty coleislazy this is just what I needed.