# Move object to mouse with limits *SOLVED*

So I’ve been working on an ability in my game where when you press a key, the playerSprite will move to current location of mouse. Now that’s easy enough to implement. What I am having trouble with is how to limit that ability in two ways:

1. Limit the ‘blink’ ability so that when the distance of playerSprite and mouse is greater than a number(say 1000 pixels) then you cannot use that ability. So I’ve tried numerous ways I can think of to implement this like using using the compare condition where it only allows to do the ability if playerSprite and mouse distance is <= 1000 pixels. It still does not seem to limit it. I’ve even tried using 1 pixel and it does not limit it. To figure out the distance from player to mouse, I used playerSprite.Distance(MouseX()MouseY()). I’m not sure this is correct, so any help?

2. Now the second limitation is to not allow the player to blink into walls and get stuck there. I’m guessing I should put an invisible object to follow the mouse around and if that is in collision with anything, then don’t allow blink but how do I make an object follow the mouse all the time?

I really hope you guys can help me if it’s even possible. TY all in advance

Mmmm… that function only works with objects ObjectA.Distance( ObjectB ), but there are two main solutions:
1- Create a little, invisible object, and allways set this object position to the mouse position (make the object follow the mouse), then you can use playerSprite.Distance( InvisibleObject )
2- Use the formula: Distance = sqrt( pow( playerSprite.X()-MouseX(), 2 ) + pow( playerSprite.Y()-MouseY(), 2 ) )
from: distance(AB) = sqrt( (A.x-B.x)^2 + (A.y-B.y)^2 )

Yeah, this is a great solution, and you will be able to use the Distance function as I had said in “1-” (the invisible object that follows the mouse should be of the same size as the playerSprite).

Add an event without conditions (so the actions will be executed allways) and add the action “Position of an object”:

``Do = MouseX() to the X position of InvisibleObject, and = MouseY() to the Y position of InvisibleObject``

Thanks for this. I was about to update my post saying that I have solved it. Here is the result:

and the event tab:

I have also updated just now the origin of the playerSprite and invisibleObject to its center so the blink is even cleaner. I just wanna ask if there’s any benefit to using the formula instead of the built in function aside from math plus points and not having to add Physics automatism?

Last of all, is there any way to detect collision with the tile(which in this case is the floor)? That is why I keep getting stuck on the floor in the gif I made.

If I’m understanding you:
-About use the formula: no, I don’t know how GD makes the computation, but surely is not very different
-Physics automatism: the platform automatism works fine without adding the Physics automatism (maybe use it internally, we could “investigate” it since GD is open source), but you could add the physics automatism and see if the game start to make “strange things”

The collision detection with tiles is through collision masks, the condition is located in “All objects” ==> “Collision”

Physics and platforms are two different engine, and most of the time if you activate physics on an object then you should stick with it and avoid all kind of manipulation that does not rely on the physics automatism actions (because it could disturb the physics simulation to move/rotate the object without using these actions).

TY All is well now, I can properly use it. Here is the kinda final blink system:

So I create the object blinkAoE when a player holds ‘e’ and destroy it when not. But for the life of me, I can’t seem to make it transparent on image creation Even when I edit the image itself to be 50% transparent, it is still solid in game since I have to make the z-order of the object to be above everything the tiles and the blocks.

Just use the action to make an object invisible after creating it and you’re done

I can’t do that unfortunately since one of my conditions in order for the player to blink to a spot in blinkAoE is the object collision. If I just make it invisible(opacity = 0), the object is still there and still has object collision so the player will be still be able to blink without pressing the blink button.

EDIT: I have solved it by changing the conditions so that it doesn’t rely on the hitbox of blinkAoE anymore instead relied on the distance of of invisibleObject and player. I could have also just as easily changed the opacity of the image itself outside the game lol sorry for the trouble