We have a series of VG onboarding tasks to show how to tackle different practical use cases using VirtualGrasp in a VR application. In VirtualGrasp SDK, they are packed in VirtualGrasp\Scenes\onboarding.

Task Description

If this video shows "This video is unavailable," please try to refresh the page.

Interaction behaviors wanted

  • We want to implement a button without using any physical components, but only use VirtualGrasp’s kinematic joints.
  • Push once a button stay in lowered position, light turn on.
  • Push another time button come back to original position, light turns off.

Tips for VR developers

  • Which joint type should be assigned to the button?
  • Which state affordance to use to allow button be switch between these two states?
  • How to determine when light should be on or off (use GetObjectJointState function)?
  • More systemtic understanding can be obtained in push interaction.


In VirtualGrasp SDK, we packed the solution of this task in VirtualGrasp\Scenes\onboarding.


using UnityEngine;
using VirtualGrasp;

 * ToggleLight shows as a tutorial on a non-physical two-stage button setup 
 * through VG_Articulation and how to use VG_Controller.GetObjectJointState to toggle light on and off. 
public class ToggleLight : MonoBehaviour
    public GameObject m_light = null;
    public GameObject m_light2 = null;
    private VG_Articulation m_articulation = null;

    public AudioSource m_audioSourceOn;
    public AudioSource m_audioSourceOff;

    private float m_state;
    private bool m_binState = false;

    void Start()
        if (TryGetComponent<VG_Articulation>(out m_articulation))
            VG_Controller.GetObjectJointState(transform, out m_state);

    void Update()
        VG_Controller.GetObjectJointState(transform, out float newState);
        if (newState != m_state)
        m_state = newState;

    void EvaluateState(float state)
        if (state == m_articulation.m_min && m_binState)
            m_binState = false;
        else if (state == m_articulation.m_max && !m_binState)
            m_binState = true;

is the script showing how to use API function GetObjectJointState to get the object’s joint state in order to determine when the light is on or off.