cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a collider pokeable via Poke Interactable

uncle_hunty
Explorer

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 1

uncle_hunty
Explorer

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.