Let's talk about the Physics Debugger in Unity and how to set up 3D Colliders and Triggers in your VRChat scene
VRChat is a well-known social platform for those with 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 the scene and manage triggers in VRChat.
Having a simple colliding setup will help calculations on low-end machines as the physics interactions will be lower and simpler.
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 it's triggering and then it can enter the other collider volume and (if set so) send a specific message. 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 come into play and behave 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.
Here, we could illustrate the scenario where the player is traversing the map and choose to enter the river. This practical example can be reflected in colliders design by defining the height at which the player is walking and implementing triggers that adjust the player's speed, gradually slowing it down as it progresses deeper into the river.
This scenario is exemplified in our Avatar Garden environment.
As the players walk through the river, they will traverse the water mesh while walking over the riverbed soil.
Types of colliders
The three types of collider interactions present in Unity are static, rigidbody and kinematic.
Each serves a specific purpose:
Static colliders: these are for GameObjects that are not meant to move or are not affected by gravity.
Rigidbody colliders: these are meant for objects that have "forces" applied to them, and thus gravity (and other possible set up forces) affects them in each frame (unless they are in sleeping mode).
Kinematic colliders: these are meant for kinematic bodies and are not driven by the physics engine.
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: this is the simplest and most commonly used type of collider, creating a bounding box that forms a collision volume around the mesh. It is suitable for almost any type of collider interaction and is perfect for trigger volumes.
Sphere collider: ideal for round or almost spherical objects that need to roll or maintain curved collision without using a mesh collider.
Capsule collider: designed for cylinder-like objects, it resembles an extruded sphere from the middle and is suitable for characters and other objects that require roundness but also need tall colliders.
Wheel collider: specifically tailored for torus-shaped objects like wheels, as the name suggest. Its primary application is in racing games or vehicles that use wheels. It applies forces to simulate realistic wheel behavior and makes it easy to configure vehicles that traverse different types of terrain or roads.
Terrain collider: functions as collider based on the data collected from the terrain GameObject.
Mesh collider: the ideal choice for non-primitive shapes that require complex collision. A quick workaround to simplify and optimize them for the engine is to enable the "convex" toggle box, which reduces the mesh collider to a maximum of 256 triangles. Additionally, this component is useful for custom colliders created within our modeling toolkit.
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.
Applying a collider to a GameObject is as simple as adding the component in the "Inspector Window" once you have your GameObject selected. You can find it in Component/Physics, but you can also search for it by using the keyword collider.
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 setting our colliders in the scene, the best way to preview and correct them prior to testing is by using the physics debugger.
You will find this window located in Window —> Analysis —> Physics Debugger.
This window will overlay the colliders on top of your meshes, as if it adding a layer of semi-transparent objects with colors that correspond to different types of colliders. It uses red for static colliders, yellow for triggers, green for rigidbody colliders and blue for kinematic colliders.
Here, you can check or uncheck to display the collision geometry, and you can also directly select your GameObjects by their collider volume using the mouse.
This window offers a couple of features to configure to assist you in configuring and sizing the colliders effectively. You can change the colours to match your preferences, adjust the transparency or set random colors to create variation between them.
The physics debugger will be your best friend for spotting flaws in your physics before playing or even after noticing errors while testing!
Triggers in VRChat
For anyone experienced enough in game development, it's known that in Unity, to activate a trigger you need a C# script that tells the engine what to do when one collider triggers another collider. The trigger bool in the collider components instructs the physics engine to allow other colliders to pass the triggered collider.
However, in VRChat, this conventional method isn't possible due to custom script limitations. Instead, triggers are managed through its event handler. Simply add the VRC_Trigger Script, and the SDK will incorporate the event handler!
From this point onward, programming in VRChat becomes more visual, and there's no need for traditional code. It's important to be aware that some aspects change, making it more "artistic-friendly", if you will.
To add a behaviour as a result of a trigger, simply click "Add" in the VRC_Trigger component and begin configuring your interactions. There arenumerous possibilities, and covering all of the is nearly impossible due to their versatility.
So, indeed, the sky is the limit. Just keep in mind that these operations can significantly impact performance if they are expensive to execute.
Applying colliders in 100Avatars Garden World in VRChat
Colliders in the 100Avatars Garden, created by Polygonal Mind (us), consist of a mix of box colliders and mesh colliders. We chose this combination to maintain simplicity and control over certain collider volumes.
However, this setup may not provide a clear reference for understanding why it's configured this way.
When working with colliders, the first two questions you should ask yourself are:
Why am I implementing a collider?
What purpose will it serve?
These two questions are crucial for minimizing collision complexity. Remember: optimizing the physics engine for smooth performance is essential to avoid artifacts in player collisions.
Collisions 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.
The large box in the background serves to prevent players from leaving the scene, ensuring that the player engagement is maintained without worrying about inadvertently breaking the scene by allowing playters to climb or explore beyond intended boundaries.
Once again, one of the best practices in doing game development, particularly regarding colliders, is to do the work manually. Don't rely solely on the engine do handle collision calculations without understanding exactly what's begin done.
Evaluating the best-suited collider for each occasion will provide you with tighter control over the debugging process and ensure that collisions behave as intended in your game.
For example, these tree logs don't use a mesh collider to accurately match their shape when the collider is engaged. But why? There's no reason to implement a complex collision here when the player only needs to recognize that there is a log in their path without any further interaction.
Another example of collider design can be seen here: it's not necessary to create a collider for every object. If we had decided to create a collider for each small rock, players would experience noticeable bumps when walking, lead to discomfort and not aligning with our intended gameplay vision. Instead, the ground is represented by a mesh collider using the same ground mesh, and the grass is non-collideable.
In our Avatar Garden, we've made some specific decisions regarding collider placement. Firstly, the trees don't have collisions on the top. This is because players can reach the high tree tops, and no primitive collider worked well for the curvature of our tree models. To address this, we created custom models specifically to fulfil yhe need for mesh collider on the tree tops.
Additionally, we've used mesh colliders for bushes and medium-sized plants. This choice was made because there was no way to use primitive-shaped colliders for such shapeless vegetation. We aimed to keep the shape all the mesh colliders as simple as possible or activate the convex option to reduce them to 256 triangles if they were higher.
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. While we've provided a comprehensive overview, you canr efer to the Unity documentation fwane information
In game development, physics, or at least basic physics, are the second stage of environment development, so always keep them in mind when building your worlds! They can truly be a game-changer in 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!
VRChat
Unity
Development
Kourtin
Head of OPS
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.