Controlling Player Mobility with PlayerMobility

This example demonstrates how to enable or disable a player's movement using PlayerMobility in a VRCStation.

How It Works:

  • Attach this script to an interactable object.

  • Assign a VRCStation in the Inspector.

  • When the object is interacted with:

    • If the station immobilizes players, it switches them to mobile.

    • If the station allows movement, it switches them to immobilized.

  • Logs the change in Unity Console.

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.SDK3.Components;

public class MobilityControl : UdonSharpBehaviour
{
    public VRCStation station; // Assign a VRCStation in the inspector

    public override void Interact()
    {
        if (station != null)
        {
            // Toggle between allowing and immobilizing movement
            if (station.PlayerMobility == VRCStation.Mobility.Immobilize)
            {
                station.PlayerMobility = VRCStation.Mobility.Mobile;
                Debug.Log("Player is now mobile.");
            }
            else
            {
                station.PlayerMobility = VRCStation.Mobility.Immobilize;
                Debug.Log("Player is now immobilized.");
            }
        }
    }
}

Last updated