Tutorial
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.

Optimizing VRChat Worlds: collision debugging

Heading
Location:
This is some text inside of a div block.
Client:
This is some text inside of a div block.
Mar 2, 2021

Let's talk about the Physics Debugger in Unity and how to set up 3D Colliders and Triggers in your VRChat scene

I WANT TO GO

VRChat is a well known social platform for all those who have VR equipment, and even if you don't have any specific hardware, you can join the party from your standard PC screen too!

Ensuring that your scene runs smoothly not only benefits you but also extends to your target audience. If you fail to democratize hardware requirements, then you fail to create a popular VRChat World.

This guide focuses on the Physics Debugger function of Unity and how to set up your 3D Colliders in scene and how to manage triggers in VRChat.

Having a simple colliding set up will help calculations on low-end machines as the physics interactions will be lower and simpler.

Resources

What are Colliders

Colliders are transparent walls that, with their components, define the shape of an object for the purposes of physical collisions. They are basically interactions between objects that send messages to the engine to determinate if the object is colliding, and therefore can't proceed to go through it; or it's triggering and then it can enter the other collider volume and (if set so) send a specific message. And it does not need to be the exact same shape as the same Object’s mesh.

To give you a better understanding: every time you get yourself into a game, the player moves or you have "physical" interactions with the environment such as dropping a glass or throwing a rock collisions are getting in to work and behaving as solids, triggers or gravity affected objects.

This sorcery: operates within default parameters, but as is the case in every game engine, you can configure colliders to your preferences to align with your desired interaction outcomes. This definition can be applied to scenarios such as walking on solid ground while gradually sinking into muddy terrain or entering a flowing river.

Colliders Essentials in Video Games

Here we could state that the player is walking along the map and decides to enter the river, this literal information could translate into colliders design in a way that define at which height the player is walking on and triggers that are modifying the player speed and turn it slower as it goes further into the river. This does indeed happen in our Avatar Garden environment:

Colliders Essentials in Video Games

As the player will walk through the river, they will pass through the water mesh walking over the river soil instead.

Types of Colliders

The three types of Collider interactions present in Unity are Static, Rigidbody and Kinematic.

Each serves a specific purpose:

  • Static Colliders. Are for GameObjects that are not meant to move or are not affected by the Gravity.
  • Rigidbody Colliders. Are meant to be for objects that have "forces" applied on them and therefore gravity (and other possible set up forces) affects them in each frame (unless they are in sleeping mode).
  • Kinematic Colliders. Meant to be for Kinematic bodies and are not driven by the physics engine.

Colliders shapes in video games

If we replicate this mockup in Unity and hit the Play button, the engine will cause the ball to fall, while the rock remains stationary. Applying a 3D Collider component to an object provides us with several options:

  • Box Collider. The simplest and most used type of collider, a bounding box that creates a collision volume around the mesh. Is suitable for almost any type of collider interaction and is perfect for Trigger Volumes.

Unity Colliders: Box collider

  • Sphere Collider. Perfect for round or almost spherical objects that have to roll or you want to keep that curvature collision without using a Mesh Collider.

Unity Colliders: Sphere collider

  • Capsule Collider. For Cylinder objects, is like an -extruded from the middle- sphere and is good for characters and other objects that require roundness but need tall colliders.

Unity Colliders: Capsule collider

  • Wheel Collider. Suitable for Torus-shaped objects like -the name itself says- wheels. Its use is focused to Racing games or vehicles that use wheels. Applies forces on it and makes it easy to configure a vehicle that runs over different types of soil or roads.

Unity Colliders: Wheel collider

  • Terrain Collider. Acts as Collider based on the data collected from the Terrain GameObject.


Unity Colliders: Terrain collider
  • Mesh Collider. The perfect option for non-primitive shapes that require complex collision. The best quick workaround to make them simpler and better for the engine is to check the "Convex" toggle box that reduces the mesh collider to 256 tris max. Also this component comes handy when it comes to custom colliders created by ourselves in our modelling toolkit.

Unity Colliders: Mesh collider

By default, the Mesh Collider will use the mesh assigned to the Mesh Filter as the representation for the Collider.

The Rigidbody component operates independently from the Collider component, providing autonomy and control over its behavior. It acts as an 'addon' to the static collider and also determines whether the Collider's interaction is Kinematic or not.

Unity Colliders: Rigidbody

Applying a Collider to a GameObject is as easy as adding the component in the Inspector Window once you have your GameObject selected. It is located in Component/Physics/ but you can also search for it by using the keyword Collider.

Unity Colliders components

What does the Physics Debugger

In Unity, the Physics Debugger is a tool used to visualize and troubleshoot the physics interactions and components in your game or simulation. It's especially valuable when working with complex physics-based systems.

After we set our colliders into scene, the best way to previsualize and correct colliders prior to testing is the Physics debugger.

You will find this window located in Window —> Analysis —> Physics Debugger.

Physics Debugger in Unity

This window will make the colliders overdraw over your meshes like if it was adding a layer of semi-transparent objects with a color that matches a type of Collider. Red for static, Yellow for trigger, Green for rigidbody and Blue for kinematic colliders.

Physics Debugger: Collision geometry

Here you can check/uncheck to display the Collision Geometry and also you can be able to Mouse Select directly your GameObjects by their Collider Volume.

Physics Debugger in Unity

This window will drop a couple of features to configure to help us out as much as possible to configure and size the colliders. You can change the colours to match the best ones for you, change the transparency or set a random to create variation between them.The Physics Debugger is going to be your best friend to spot flaws in your physics prior playing or even after noticing errors while testing!

Triggers in VRChat

For anyone experienced enough in game development will know that in Unity to activate a trigger you need a C# script telling the engine what to do when one Collider Triggers another Collider. The Trigger bool in the Collider Components tells the physics engine to let the other colliders go through the triggered.

This is not possible in VRChat due to the custom script limitations and so it manages trigger by its Event Handler. Just add the VRC_Trigger Script and the SDK will add the Event Handler!

VRChat trigger in Unity

From this point, programming in VRChat turns visual and no real code is needed. Just to be aware that some stuff changes from place and it turns more "Artist friendly". You know.

VRChat trigger in Unity

To add a behaviour as a result of a trigger, just click Add in VRC_Trigger component and start configuring your interactions. There are so many that covering a general use of this Triggers is barely impossible. So yes, the sky is the limit. Just remember that this operations can impact performance badly if they turn out to be expensive to execute.

Applying Colliders in 100Avatars Garden world in VRChat

Colliders in 100Avatars Garden made by Polygonal Mind (us) are a mix of Box Colliders and Mesh Colliders because we wanted to keep it simple and under our control on some other collider volumes. But that is not a clear reference to understand why is like this.

When you get your hands on colliders, the first question you have to ask yourself is:

  • Why I'm doing a Collider?
  • What is going to do my Collider?

VRChat 100Avatars Garden

These two questions are essential for maintaining minimal collision complexity. Because, remember: you'll want to optimize the Physics engine for smooth performance to avoid artifacts in player collisionsCollisions should be driven by gameplay considerations. There's no need to create a collider for every object in the scene. Instead, envision how players will interact, or how you intend them to interact, and tailor your colliders accordingly.

100Avatars Garden VRChat world

Collision Complexity in 100Avatars Garden VRChat world

The big box in the back is to avoid players from going out the scene, engaging the player is a good way to free them to climb whatever without thinking of getting to the point of breaking the scene.

Once again, one of the best practices in doing game development but this time on Colliders is doing the work by hand. Don't let the engine do the math for you without telling exactly what's doing. Evaluating the best suitable collider in each occasion will give you tighter control over the process of debugging.

Mesh Collider match shape VRChat

For example this tree logs doesn't use a Mesh Collider to correctly match their shape when the collider comes to work, but why? There is no reason to spend a complex collision here when the player will just want to notice that there is a log in their way but nothing else.

Mesh Collider match Shape VRChat

Another example on Collider design goes here, you dont need to create a collider for everything. If we would have decided to create a collider for each small rock, the player would notice little bumps when walking and would be very uncomfortable or at least it wouldn't match the playable vision we had. Instead the ground is a Mesh Collider of the same Ground Mesh and the grass is not collideable neither.

Collider tree design VRChat

And the last practical examples we are showing here, I want to point out that our trees in the Avatar Garden have not collisions on the top. Because any player can reach the high tree tops and no primitive collider worked good for the curvature of our model; we decided to create a custom model just to fulfil this Mesh Collider need.

Other things that we decided to use Mesh Colliders where Bushes and medium-sized plants. This was because there was no form to use primitive shaped colliders for such shapeless vegetation. We tried to keep as simple as possible the shape of all the Mesh Colliders or activate the Convex option to reduce to 256 tris if it was higher.

Simple Mesh Colliders in a rock

All about Colliders

Physics and collisions are critical elements in game and virtual world development. Understanding how to apply them effectively can have a profound impact on gameplay and user experience. Here you have the Unity documentation if you want more information, (although we have taken care of chewing it for you).

In collision, when it comes to game development, physics, or at least basic physics are the second stage of an environment development so keep them always in mind when building your worlds! They can be a truly game changer on how the experience is felt and enjoyed.

By designing your game environments with attention to physics and collisions, you can create more immersive and engaging experiences for players, ultimately contributing to the quality and success of your project.

Remember: keep it simple but also keep it clever!

I WANT TO GO
VRChat
Unity

How to access

Kourtin
ENVIRONMENT ARTIST

I purr when you're not looking. I'm passionate about environments and all the techie stuff to make them look rad. Learning and improving everyday to be a better hooman.

Tutorial
Creating a VRChat avatar with blend shapes visemes
Tutorial
Add dynamic bones to your 3D character in Unity
Tutorial
How to add emissives and lights to Hyperfy for GLB archives