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 Light m_light = null;
    private VG_Articulation m_articulation = null;

    void Start()
        m_articulation = GetComponent<VG_Articulation>();

    void Update()
        float state;
        VG_Controller.GetObjectJointState(transform, out state);

        float disable_state = (m_articulation.m_discreteStates.Count == 0) ? m_articulation.m_min : m_articulation.m_discreteStates[0];
        if (state == disable_state) 
            m_light.enabled = false;
        else if (state == m_articulation.m_max)
            m_light.enabled = 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.