Forum rules - please read before posting.

Trigger on touch exit?

Hey there

I have been doing a little jigsaw game using draggables and a trigger and when entering that trigger, teleporting the touched piece away and teleporting the "solved" piece into the spot.
Right now whenever I drag the item into the trigger it gets triggered ...is there a way to have it triggered instead when pulling the finger of the screen? Just so it feels more like it was a choice and not just dragging it all around and then it triggers.

Any direction would be much appreciated
Best, Dan

Comments

  • You can assign an "Interaction on let go" ActionList in the Draggable Inspector, which will run when the player releases it.

    You'd also have to create a means of knowing if the Draggable is currently inside the Trigger at the time. One approach would be to create a pair of Triggers (Enter and Exit) in the same space that set a Bool variable True/False as the object enters and exits it.

    Though, it's easier to just script the whole thing. Releasing a Draggable object also fires the OnDropMoveable custom event, which can be used to run a new Cutscene that snaps it to the correct position if it's inside the boundary of a given trigger Collider:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class SnapDraggableInTrigger : MonoBehaviour
    {
    
        public Collider triggerCollider;
        public Cutscene cutsceneOnRelease;
    
        private void OnEnable () { EventManager.OnDropMoveable += DropMoveable; }
        private void OnDisable () { EventManager.OnDropMoveable -= DropMoveable; }
    
    
        private void DropMoveable (DragBase dragBase)
        {
            if (dragBase.gameObject == gameObject && triggerCollider.bounds.Contains (dragBase.transform.position))
            {
                cutsceneOnRelease.Interact ();
            }
        }
    
    }
    

    To use, paste into a C# file named SnapDraggableInTrigger and attach to your Draggable, and assign the Trigger and Cutscene in its Inspector. Mind that it only detects the Trigger if the Draggable's root position is inside the Trigger's bounds - so you may have to increase the size of the Trigger for it to work.

  • edited February 2021

    Thank you so much Chris!
    As always, much more feedback than one would have expected.
    The "interaction on let go" is only accessible with the lock to track drag mode - so it can't be used if its being used with "moving along plane" (as would be the case for the jigsaw game in my case - the pieces can be moved freely around)
    Thanks for the script, will be very handy - just curious about the other solution too, since I might need a similar solution for some other ideas.

    Best, Dan

  • The "interaction on let go" is only accessible with the lock to track drag mode

    Good point. I'll look to see if this can be amended.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.