[SOLVED]How to do Raycasting with Leap Motion?
I am currently try to cast the ray from the Leap Motion hand to control player's movement, and then I found this codelink text
but when I paste in my project, it keeps give me NullReferenceException
"NullReferenceException: Object reference not set to an instance of an object HandRaycast.Start () (at Assets/Script/HandRaycast.cs:25)"
Here is the code
using Leap;
using Leap.Unity;
using System.Collections.Generic;
using UnityEngine;
public class HandRaycast : MonoBehaviour {
Hand leapHand;
FingerModel finger;
HandModel handModel;
// Use this for initialization
void Start()
{
/*Controller controller = new Controller();
Frame frame = controller.Frame(); // controller is a Controller object
if (frame.Hands.Count > 0)
{
List<Hand> hands = frame.Hands;
leapHand = hands[0];
}
finger = leapHand.Fingers;
Finger.FingerType fingerType = finger.Type;*/
handModel = GetComponent<HandModel>();
leapHand = handModel.GetLeapHand();
if (leapHand == null) Debug.LogError("No leap_hand founded");
}
// Update is called once per frame
void Update () {
Vector3 fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
for (int i = 0; i < HandModel.NUM_FINGERS; i++)
{
finger = handModel.fingers[i];
if (Physics.Raycast(finger.GetTipPosition(), fwd, out hit))
{
float distanceToGround = hit.distance;
Debug.Log("hit something" + distanceToGround);
}
Debug.DrawRay(finger.GetTipPosition(), finger.GetRay().direction, Color.red, Time.deltaTime, true);
}
}
}
Do any one know the solution?
Moreover, do anyone know how to scale OSVR VRFirstPersonController without canvas position affected? Everytime I adjust VRFirstPersonController scale, I do not know why the canvas on VREye1 always disappear.
Answer by YugiyOIzayoI · Feb 20, 2018 at 02:02 AM
This issue already solved. I do not know why it does not work at first.
"Just attach the script to the Handmodel"
But even I turn on Gizmos I still not see the ray...
Your answer
Follow this Question
Related Questions
Raycasting through UI Image with transparent part 5 Answers
Select from multiple character to move 0 Answers
Ray-casting Problem 0 Answers
Raycast positioning problem 1 Answer
RayCast Rotation 1 Answer