Forum Discussion
uncle_hunty
2 years agoProtege
How to make a collider pokeable via Poke Interactable
I wanted to make an object's collider pokeable from any direction via PokeInteractable, but I had a really hard time figuring out how to do it (mostly because the Unity Meta XR API is hard to find and impossible to navigate).
I finally figured it out, so I'm posting it here for the next person who's having trouble with it:
PokeInteractable wants an ISurfacePatch rather than an ISurface, which is really confusing because the class names for both are just "FooSurface"; e.g. "SphereSurface" is an ISurface, but "CircleSurface" is an ISurfacePatch!
So, you've added a ColliderSurface with a reference to your object's collider, but it won't let you drag that into the "Surface Patch" slot on PokeInteractable. The solution is that you have to roll your own ColliderSurfacePatch, but fortunately that's really easy to do. Here it is:
using Oculus.Interaction.Surfaces;
using UnityEngine;
public class ColliderSurfacePatch : MonoBehaviour, ISurfacePatch
{
public ColliderSurface surface;
public ISurface BackingSurface => surface;
public Transform Transform => surface.Transform;
public bool ClosestSurfacePoint(in Vector3 point, out SurfaceHit hit, float maxDistance = 0)
{
return surface.ClosestSurfacePoint(point, out hit, maxDistance);
}
public bool Raycast(in Ray ray, out SurfaceHit hit, float maxDistance = 0)
{
return surface.Raycast(ray, out hit, maxDistance);
}
}
As you can see, all this does is hold a reference to the ColliderSurface, and just pass along everything to that.
So now you can just drag your ColliderSurface into the "Surface" slot, then plug the ColliderSurfacePatch into your Poke Interactable's "Surface Patch" slot, and it'll magically work! Even hovering works! Hooray!
It's crazy that they don't already have this class (or just make PokeInteractable work with ISurface rather than ISurfacePatch!). It's probably really non-performant to use it with a bunch of objects in a scene, but it's probably fine for just having a few.
1 Reply
Replies have been turned off for this discussion
- uncle_huntyProtege
The current downside is that there's a thin "skin" around the collider, and as soon as your finger goes through the skin the Poke Interactable fires an Unselect event, and you have to take your finger all the way out of it and poke it again before it'll register a new Select.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 7 months ago
- 9 months ago
- 2 years ago
- 5 years ago