Using Simple Colliders for Complex Shapes

Shane Makanui-Lopes
2 min read1 day ago

--

For my next VR experimentation, I’m going to program a shooting range. First step for a shooting range…picking up the gun.

Unlike the basketballs, the gun is a more complex shape than a pill or box. So my solution here is to use multiple colliders to give the gun an approximate shape/presence in the scene.

Colliders in the Unity editor

As seen above, I used a pill collider in the handle of the gun, and a box collider for the rest of the body.

Note: In this case, the gun has multiple child objects for it’s barrel, hammer, etc. So I attached the body box collider to the barrel child object.

Now I don’t necessarily want the players to be able to grab the gun by the barrel (would defeat the point and make things confusing). But I do need the collider there so it interacts with the table and other solid objects in a logical way.

So to limit the grabbable interaction to the barrel, I had to adjust a field in the code:

Under the XR Grab Interactable script, I limited the Colliders portion to just the Capsule Collider I used for the handle.

Now the gun can be grabbed at whatever angle by the handle, but the barrel does not interact with your hands (though it does with the table)

--

--