- Home /
How can I return a Dragged Object From a Layer Group to its Original Position?
I'm trying to work on a card system, I have a drag system going nicely and the cards are setup on a horizontal layer group, however, when the player drops the card outside of the "casting area" I would like it to return to it's original position before it was dragged. Because of the layer group, even though I'm storing the original position having it go back to it produces funkiness and going below the "card hand" area.
I've tried Update and Coroutine approaches using something like this:
IEnumerator CardReturn(Transform card, Vector3 destination, float speed)
{
while (transform.position != destination)
{
card.position = Vector3.MoveTowards(
card.position,
destination,
speed * Time.deltaTime);
yield return null;
}
transform is the object transform and destination is the original position of the object placed at the start method.
Edit: To clarify, I don't want it to "snap back", I actually want the card to physically move from where it is to its starting point.
Any help greatly appreciated!