Skip to main content
Up and Coming
December 21, 2019

Hand Tracking Button Trigger Zone

Try to use the button prefab "NearFieldButton" from the new oculus integration V12.0 package. Problem is the "Interactable State Changed(InteractableStateArgs)" in Button Control panel can be triggered by all three collider zones(Proximity, Contact, Action), whichever touched first. Anyone knows how to trigger the event on Action zone only? Thanks in advance!

    12 replies

    Up and Coming
    December 23, 2019
    Could you just make the action zone bigger then the other zones or shrink the other zones down?
    Theres a bug with the Ray casting though where proximity doesn't work. Shrinking it down will only fix the poking tool.
    Up and Coming
    December 23, 2019
    I recommend a helper script to split these events

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using OculusSampleFramework;
    using UnityEngine.Events;

    public class ButtonListener : MonoBehaviour
    {

        public UnityEvent proximityEvent;
        public UnityEvent contactEvent;
        public UnityEvent actionEvent;
        public UnityEvent defaultEvent;

        // Start is called before the first frame update
        void Start()
        {
            GetComponent<ButtonController>().InteractableStateChanged.AddListener(InitiateEvent);
        }

        void InitiateEvent(InteractableStateArgs state)
        {
            if (state.NewInteractableState == InteractableState.ProximityState)
                proximityEvent.Invoke();
            else if (state.NewInteractableState == InteractableState.ContactState)
                contactEvent.Invoke();
            else if (state.NewInteractableState == InteractableState.ActionState)
                actionEvent.Invoke();
            else 
                defaultEvent.Invoke();
        }

        // Update is called once per frame
        void Update()
        {
            
        }
    }

    Up and Coming
    December 23, 2019
    Hi Quacklin, Thanks a lot for the detailed solution! It works perfectly! BTW, do you have any suggestion of how to add the grab function? 
    Up and Coming
    December 23, 2019
    I'm struggling with the same question   :'(
    The same with getting the bone gameobjects to link my custom collier. I thought that would be more easy to get a grab function. 
    Up and Coming
    December 23, 2019
    Okay got it.
    The script Hand on the spawned object HandRight and HandLeft have a function called "PinchStrength" with a Enumerator for "Index, Middle, Ring, Pinky and Max( haven't figured out what max does). They return a value between 0 and 1 when the get closer to the thumb. 
    I just used that to trigger an event when at least two values are 1 then grabbing is active. Everything less is release.
    Up and Coming
    December 23, 2019
    Do you mean the section in hand.cs?
    Up and Coming
    December 23, 2019
    I think so. Unfortunately i'm not a programmer and using visual scripting to get anything to work.

    Up and Coming
    December 23, 2019
    Unfortunately me neither,  :D what's this visual scripting tool you are using? 
    Up and Coming
    December 23, 2019
    It's called Bolt
    Up and Coming
    December 23, 2019
    Got it. Thanks! Let me check it out.