XR Ray Interactor #97
Replies: 3 comments 1 reply
-
I will tag this as using Nova;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.Interaction.Toolkit.UI;
public class NovaRaycaster : BaseRaycaster
{
public Camera Cam = null;
public override Camera eventCamera => Cam;
public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
{
if (!(eventData is TrackedDeviceEventData trackedEventData))
{
return;
}
List<Vector3> rayPoints = trackedEventData.rayPoints;
for (var i = 1; i < rayPoints.Count; i++)
{
Vector3 from = rayPoints[i - 1];
Vector3 to = rayPoints[i];
float rayDistance = Vector3.Distance(to, from);
Ray ray = new Ray(from, (to - from).normalized * rayDistance);
// Raycast against Nova content
if (!Interaction.Raycast(ray, out UIBlockHit hit, rayDistance))
{
continue;
}
RaycastResult castResult = new RaycastResult
{
gameObject = hit.UIBlock.gameObject,
module = this,
distance = (hit.Position - from).magnitude,
index = resultAppendList.Count,
depth = 0,
worldPosition = hit.Position,
worldNormal = -hit.Normal,
};
resultAppendList.Add(castResult);
trackedEventData.rayHitIndex = i;
break;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Thank you - Assets\Nova\Scripts\Personal\NovaRaycaster.cs(6,22): error CS0234: The type or namespace name 'Interaction' does not exist in the namespace 'UnityEngine.XR' (are you missing an assembly reference?) If I changed the include to be just UnityEngine.XR
I have the XR toolkit and XR interaction framework installed - this is just a blank project with Nova. The ray line is as below: What I may do as a temp workaround is have the native blank Unity canvas overlayed in front of the Nova UI block, so that at least the ray line is truncated until I can figure it out correctly. |
Beta Was this translation helpful? Give feedback.
-
@dkonik I tried the code you provided and while it works when the UI isn't moving, if the UI moves or is child of an object that moves in FixedUpdate, the reticle keeps jumping around. I have a Unity canvas next to it, and when I hover on it, the laser/reticle behaves correctly. I'm guessing it's something about when Nova updates and Interaction.Raycast works. Do you have any idea on how to make it work? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the standard XR Ray interactor - the Nova UIBlock is not recognised by the line renderer for culling.
The button does work, and is selectable via the controller button, using the example Nova Input Manager XR script
(Although I will need to make it work via the Trigger - but that's another thing).
Line render culling via the Unity Canvase
Line render passing through the Nova UIBlock2D
Beta Was this translation helpful? Give feedback.
All reactions