Skip to main content

Update Station Position Logic

Now that we know when someone is in the station, and if that player is local vs remote, we can update the station objects appropriately.

  1. Add a public Transform variable. This will be set with the origin we created earlier. 
  2. Add the Update event. The first thing we need to check is if the sitting player is valid. If they are invalid, we can stop early as no one is using the station. 
  3. Next, check if the player is the local player. In both the local and remote case, we will need to perform some math. Create a custom event for updating position for local and remote.

Update Loop UdonGraphUpdate Loop UdonSharpUpdate Loop CyanTrigger

First, updating positions for the local player. Get the local player's position and rotation, and set the station's location to these values. Having the station follow the local player removes issues with teleporting on exiting the station.

Next, get the origin transform's "worldToLocalMatrix". This 4x4 matrix will convert world space coordinates into the local space coordinates relative to this origin object. Use matrix.MultiplyPoint on the player's position to get the local position. Use matrix.get Rotation and multiply this with the player's rotation to get the local rotation. Now set the ObjectSync object to this position and rotation.

Updated Variables UdonGraphUpdate Local UdonGraphUpdate Local UdonSharpUpdated Variables CyanTriggerUpdate Local CyanTrigger

Now to handle updates for the remote player. We basically need to do the opposite here. 

First get the position and rotation of the objectSync object. Also get the origin transform's "localToWorldMatrix". Note this is local to world and not world to local like the previous one. Use matrix.MultiplyPoint on the sync's position to get the new world position. Use matrix.get Rotation and multiply this with the sync's rotation to get the new world rotation. Finally, set the station's location to this position and rotation.

Update Remote UdonGraphUpdate Remote UdonSharpUpdate Remote CyanTrigger

With those events created, we need to go back and add two send custom events in previous areas. Since players will teleport when entering and leaving stations, we can reduce movement by updating the station position just before entering and just after exiting. In the "_EnterStation" event, just before entering the station, add SendCustomEvent to the local update position event. In the OnStationExit, check if the player was local, and also add the SendCustomEvent

Update EnterStation UdonGraphUpdate OnStationExited UdonGraphUpdate EnterStation UdonSharpUpdate OnStationExited UdonSharpUpdate EnterStation CyanTriggerUpdate OnStationExited CyanTrigger

With this, one player can enter the station, and other players can observe them walking on the wall. 

VRChat_4QFrDRku9h.gif