Unity VR: Body Collisions
Intro
With controller tracking and locomotion, we are getting closer to our complete virtual body form, except for the ability to walk through everything. No, this is not a game mechanic. We want to give our player rig or XR Origin the ability to detect collisions.
Colliders
Typically to detect collisions, we could attach some sort of collider to the object(s) we want collision detection on, but there is a problem. The XR Origin is not a static object. It moves and changes size dynamically based on the player’s headset and body movement. A regular Collider won’t automatically adjust to follow the player’s real-world movement like crouching, leaning, or looking around corners.
So if the player crouches down in VR, their head might clip through the floor or walls because the Collider doesn’t shrink or move with them.
If you make the Collider big enough to cover all possible movements, then it feels inaccurate or clunky and creates awkward collision behavior. You will need to manually update the position and size of the colliders in code.
It’s important to note that for collision to function correctly, a Rigidbody component must be added to the collider. This incorporates the object into the physics engine, which can introduce its own complexities. However, there is a straightforward solution available for all of this.
Character Controller
When you add the XR Body Transformer, you can add a standard Unity Character Controller component to your XR Origin (or player rig).
The Character Controller is a built-in Unity component used for player movement and collision without using physics (Rigidbody).
It provides:
- Capsule Collider — Dynamically defines the player’s shape for collisions
- Move() function — Handles movement based on inputs
- Built-in Slope Handling — Auto-handles stairs/ramps/slopes
- No Rigidbody Needed — No physics forces (like gravity/drag) unless you script it
You can add the Character Controller with the XR Body Transformer because they work in tandem. Like peanut butter and jelly.
The Character Controller provides collision detection, and the XR Body Transformer updates its size/position based on the player’s real-world movement and makes sure you fit in your VR body.