Prismic247 / ScaledColliderSystem

Scaled Collider System prefab for VRChat worlds, to allow for player interactions with world colliders that are scaled relative to your avatar size.
https://prismic247.github.io/ScaledColliderSystem/
MIT License
8 stars 0 forks source link
prefab vrchat

Scaled Collider System

Prefab for VRChat worlds to allow for player interactions with world colliders that are scaled relative to your avatar size. PC and Quest compatible. Future support planned for height specific scaling when crouching/going prone.

About

When playing VRChat, your player's physical collider is always the same size regardless of your avatar's size or the scale it's set to. While this helps maintain a consistent user experience, it comes at the cost of immersion, and limits the kinds of worlds creators can make. Want to experience an Alice in Wonderland type world where you might get scaled down and able to run into a mouse hole or under a bed, or scaled up and able to step over buildings? While there are some present solutions such as selectively disabling colliders (tedious), scaling up or down the world (requires all player at the same scale or else positional desync occurs), or the use of stations (complex and with their own set of issues).

Given the options, I decided to add another to the mix that doesn't use any stations, works independently on each user without requiring synchronization, and works in a simple drop-in prefab capacity. Simply install the package, include the prefab in your hierarchy, specify a parent world object, configure any other values, and it should work.

The result is the scale set on the player should match their collisions with the world. Optional features also included are the ability to scale the player movement/physics to their size, scale their volume, control manual scaling and min/max sizes, enabling/disabling the system altogether, switching out the scalable world parent, etc.

Demo

You can see the system in action in the world Scalable Avatar Collider Demo

Installation

Add to VRChat Creator Companion

Alternatively, go to Releases on the right and download the latest the zip or unitypackage.

Setup

  1. Install the package above into your VRChat Unity world project and add the Scaled Collider System prefab to your project hierarchy. The prefab can be found under Packages/com.prismic247.scaledcolliders.
  2. Define the World Parent object on the prefab. This is a game object which contains the world colliders you want scaled. DO NOT include the world descriptor, scripts, etc, since this can cause some performance issues such as frame drops, logic running twice, etc. Ensure any colliders you intend to use aren't set to Static. In practice and for performance reasons, try to limit it to objects with colliders that the players will interact with and move around. An enclosed room can likely exclude the floor or ceiling for example, there's no need to scale video players and canvases, etc.
  3. Define the other parameters as fits for your use case, such as default eye height, whether players can scale themselves and within what bounds, whether or not to scale player speed alongside size, to scale voice/audio, etc. Each element has a tooltip, and should be fairly self explanatory for what they do.

Optional Steps

Known Issues / Important Notes

Udon# Public API

Alongside the configurable properties, the following functions are made available to further control the behavior.

float GetLocalPlayerScale()

Returns the local player's scale relative to the base eye height. Get the inverse of this value for the local world scale (1 / GetLocalPlayerScale()).

float GetPlayerScale(VRCPlayerApi player)

Returns a given player's scale relative to the base eye height. Get the inverse of this value for the player's world scale (1 / GetPlayerScale(player)).

bool ToggleScaledColliders(bool state)

Sets the enabledScaledColliders state, and returns the state afterwards. Certain conditions such as a missing worldParent may cause this to reject attempts at enabling, hence the return value.

bool ToggleColliderGhosts(bool state)

Sets the showColliderGhosts state, and returns the state afterwards. Enabling this without having a ghostMaterial set will simple not render the objects, and it will also not work when enabledScaledColliders is disabled.

void InitializeScaledColliders(GameObject newWorldParent = null)

This allows you to swap out the worldParent for a new one, or to reset the current one if the parameter is null. The old parent will automatically be restored to its original state.