[Solved] How to make draggable object return to its original position

I have very little idea about how to achieve this:

First, the user can drag an object from its original position to anywhere.

Then, when they decide that this is not the object they want, they can drag the object back.

Lastly, when the object gets dragged close enough to its original position (in other words, the game captures the player’s intention that they want to throw it back), it will automatically go back to the exact original position (like a tween effect).

Here is the code I have right now. Since NewSprite 15 originally is in NewSprite 9, now I can’t even drag it out. Many thanks!

There are many different ways. Here are 2. (these work for a single object or multiple instances)

At the start, it sets the object variables LastX and LastY to the current position.
The first one moves it back if the right mouse button is pressed
The 2nd one checks the distance to LastX,LastY using the compare 2 numbers condition.

Object variables
(You can set the values manually or use the action as in my example. Either way, if you set them up or declare them then you don’t need the Variable() part.

The compare 2 numbers condition.

There’s also a cancellable draggable behavior but it only undoes the last drag.

2 Likes

I’d store the original position of the object at the start of the scene, and then check the distance between that and the drop position. If it’s below a certain threshold (20 pixels in my example below), set the position back to the original:


[Edit]
Haha, it’s pretty much the same as @Keith_1357’s answer, just a few minutes slower :smiley:

2 Likes

Thank you both!! MrMen’s answer was shorter and so I looked at it first and had a clear direction. Then I realized that some details in it weren’t clear to (a beginner like) me, and Keith’s answer just filled the gap :wink:

I was able to apply these to an object group. Thanks a ton!

2 Likes