cancel
Showing results for 
Search instead for 
Did you mean: 

Add ray cast from the hand in Unity

alexvilch
Protege
Simple question: for Oculus Avatar SDK how do I add the ray coming from the hand ( left or right ) if I take Avatar SDK for Oculus Unity "Controllers" scene, just simple hands.
In order to interact with other objects I would need to add event systems and canvas found examples for those but unable to find a clear explanation how to add this to Avatar hands just want to cast the ray from the hand. I'm using the latest Avatar SDK and the latest Unity 2017.3.f1
 Thank you,
Alex
24 REPLIES 24

alexvilch
Protege
Does anyone know the practical example of how to call GetHandTransform function in Avatar SDK ?

When I call it I'm getting:

error CS0246: The type or namespace name `HandType' could not be found. Are you missing an assembly reference?

Am I supposed to add more of this global include to be able to call it ?

using UnityEngine;
using Oculus.Avatar;
using Oculus.Platform;
using Oculus.Platform.Models;
using System.Collections;
 
 Thank you,

Alex


alexvilch
Protege
I'm trying to call it :   Transform raycastOrigin = GetHandTransform(OvrAvatar.HandType.Left, OvrAvatar.HandJoint.HandBase);

 Getting this:

error CS1644: Feature `using static' cannot be used because it is not part of the C# 4.0 language specification

Alex


alexvilch
Protege
Found the definition of this function in LocalAvatar in "Ovr Avatar" script

public Transform GetHandTransform(HandType hand, HandJoint joint)
    {
        if (hand >= HandType.Max || joint >= HandJoint.Max)
        {
            return null;
        }

        var HandObject = hand == HandType.Left ? HandLeft : HandRight;

        if (HandObject != null)
        {
            var AvatarComponent = HandObject.GetComponent<OvrAvatarComponent>();
            if (AvatarComponent != null && AvatarComponent.RenderParts.Count > 0)
            {
                var SkinnedMesh = AvatarComponent.RenderParts[0];
                return SkinnedMesh.transform.Find(HandJoints[(int)hand, (int)joint]);
            }
        }

        return null;
    }

Alex

alexvilch
Protege
I've figured out the correct syntax to call GetHandTransform:
 Transform raycastOrigin = myAvatar.GetHandTransform(OvrAvatar.HandType.Left, OvrAvatar.HandJoint.HandBase);

Still no ray appears from Avatar left hand.
Am I supposed to add Canvas and EventSystem ? What if I just want to cast the ray from Avatar left hand ?
Still can not figure out how to make it working. I think this AvatarSDK is lacking some simple examples so Developers can start using this.

 Thank you,

Alex

alexvilch
Protege
I was able to add the laser pointer ( ray cast ) to Avatar SDK. It goes to the left or right hand but not to the "fingers".
Moreover I do not even have to call this:
Transform GetHandTransform(HandType hand, HandJoint joint)
Working without this, I've tried to replace Handjoint.Handbase with any values below, still the ray is coming out from the middle of the hand, not like in Oculus Dash home.








public enum HandJoint

    {

        HandBase,

        IndexBase,

        IndexTip,

        ThumbBase,

        ThumbTip,

       

        Max,

    }

 Once again, does Avatar SDK Supports adding the raycast attached to the finger not to the entire Handbase ?

 Thank you,


Alex


Lightowl
Explorer
Just curious, did you figure this out?

alexvilch
Protege
Yes, I did. Just add vizualizer object with the ray and it started casting the ray from "active" hand: switching the trigger on the touch controller shifts the ray from one hand to another. None of the functions mentioned above working. You could copy it from this example:


I could not figure out how to cast the ray from the index finger like in Dash home in my case its coming from the base of the hand: from my understanding this requires making changes to the Animation of the hands.

Do not bother about those Transform functions and etc. it's simply not working.

Alex

Lightowl
Explorer
Thanks!

vikneshtk
Honored Guest
Hi
Reactivating this issue, as I am facing a similar problem to what @alexvilch was facing. I have successfully implemented raycasting from hand but not from fingers. However, the raycasting is not pointing to the forward direction. It always points in one direction. I do not want to use the Oculus raycasting, as I have faced some issues with that. I wanted to create my own raycasting. I have also added linerenderer to show my laser ray. I have given the script below and few screenshots.
using UnityEngine;
using UnityEngine.UI;

public class CustomLaserPointer : MonoBehaviour
{
public LineRenderer laserLineRenderer;
public float laserWidth = 0.1f;
public float laserMaxLength = 5f;
OvrAvatar ovrAvatar;

//OVRCameraRig cameraRig;
public Text text;

void Start()
{
Vector3[] initLaserPositions = new Vector3[2] { Vector3.zero, Vector3.zero };
laserLineRenderer.SetPositions(initLaserPositions);
laserLineRenderer.SetWidth(laserWidth, laserWidth);
//cameraRig = FindObjectOfType<OVRCameraRig>();
ovrAvatar = FindObjectOfType<OvrAvatar>();
}
void Update()
{
if (OVRInput.Get(OVRInput.RawTouch.RIndexTrigger))
{
ShootLaserFromTargetPosition(/*cameraRig.rightHandAnchor.localPosition*/
ovrAvatar.HandRight.transform.position, Vector3.forward, laserMaxLength);
text.text = "laser pointer triggered"; //debug text
laserLineRenderer.enabled = true;
}
else
{
text.text = "";
laserLineRenderer.enabled = false;
}
}
void ShootLaserFromTargetPosition(Vector3 targetPosition, Vector3 direction, float length)
{
Ray ray = new Ray(targetPosition, direction);
Vector3 endPosition = targetPosition + (length * direction);
if (Physics.Raycast(ray, out RaycastHit raycastHit, length))
{
endPosition = raycastHit.point;
}
laserLineRenderer.SetPosition(0, targetPosition);
laserLineRenderer.SetPosition(1, endPosition);
}
}

vikneshtk
Honored Guest
erg5k7ndz6wz.pngkeb2t3q48j8d.jpgwa62v48tuwcz.jpgzjxxekg9juu9.jpg