Nov
4
2015

Leap Motion: Get Finger Position & Direction

leap_motion_unity_get_finger_position_direction_scene_1

Took a while to find info on how to simply get the Leap hand finger positions in unity,
here’s cleaned up script to draw rays from fingertips to their pointing direction.

 


/******************************************************************************\
* Copyright (C) Leap Motion, Inc. 2011-2014. *
* Leap Motion proprietary. Licensed under Apache 2.0 *
* Available at http://www.apache.org/licenses/LICENSE-2.0.html *
\******************************************************************************/
// Original script: "MagneticPinch.cs" modified by unitycoder.com to just get the finger position & directions
using UnityEngine;
using System.Collections;
using Leap;
public class GetLeapFingers : MonoBehaviour
{
HandModel hand_model;
Hand leap_hand;
void Start()
{
hand_model = GetComponent<HandModel>();
leap_hand = hand_model.GetLeapHand();
if (leap_hand == null) Debug.LogError("No leap_hand founded");
}
void Update()
{
for (int i = 0; i < HandModel.NUM_FINGERS;i++)
{
FingerModel finger = hand_model.fingers[i];
// draw ray from finger tips (enable Gizmos in Game window to see)
Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red);
}
}
}


Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.