Does Physics.Raycast not work for the Vision Pro Simulator when paired with the Play to Device app? It seems that it works with the Play window in the Unity Editor but not within the Xcode Vision Pro Simulator itself.
Normally, I’d use a touch event to place an object at a specific position. However, I need to extract the normal information of the object being touched from the event and the only way that I have found how to do that is through a Physics.Raycast event.
Any assistance that anyone could provide me is greatly appreciated. Thanks!
1 Like
I solved my own problem. On the Play to Device app on the Xcode Vision Pro simulator, keep in mind that the startInteractionRayDirection will not work, so you will need to convert the ray direction yourself using your starting position and the interactionPosition in the PolySpatial EnhancedTouch event.
1 Like
Can you please share the line of code of your Raycast? I can’t get it to work. Here is what I got so far:
if (Physics.Raycast(primaryTouchData.startInteractionRayOrigin, primaryTouchData.startInteractionRayDirection, out hit, 100))
{
// TODO: check for NavMesh component
MoveCharacter(hit.point);
}
You can set up your rays for raycasting using the interactivePosition and the inputDevicePosition vectors.
var rayStart = new Vector3(primaryTouchData.interactionPosition.x, primaryTouchData.inputDevicePosition.y, primaryTouchData.interactionPosition.z);
if (Physics.Raycast(new Ray(rayStart, Vector3.down), out tempHit, 100)
{
MoveCharacter(tempHit.point);
}
Hope this helps!
1 Like
Thanks for the prompt reply!
Although it doesn’t work. Doesn’t the first parameter has to be the origin (rayStart), meaning the camera? And the second the direction?
I don’t understand why primaryTouchData.startInteractionRayOrigin
is (0,0,0). I was expecting the coordinates of the camera. Nevertheless I am working with VolumeCamera, so things might be different.
Since the interactionPosition is the position of the clicked position, I can directly move character there (and this works perfectly for my use case):
MoveCharacter(primaryTouchData.interactionPosition);
Raycasts will work on GameObjects that have a collider component defined. If you don’t have a collider component on the object you are trying to interact with, this is why Raycasts may fail for you.
When creating a ray, the first parameter corresponds to the start location of the ray (origin) and then the second parameter is the direction of the ray.
The startInteractionRayOrigin being undefined is another PolySpatial bug that will be addressed at a later date.
1 Like
Following worked better for me, since Vector3.down is a fixed direction:
var rayStart = new Vector3(inputDevicePosition.x, inputDevicePosition.y, inputDevicePosition.z);
var direction = primaryTouchData.inputDevicePosition - rayStart;
Ray ray = new(rayStart, direction);