Skip to main content

PlayerPositionRestrictor

A class in Root.Township, the global namespace.

Client: keeps the local player within a radius of this object. If the player moves too far, it moves them back to a target point with a recovery move.

Constructors​

MemberWhat it is
PlayerPositionRestrictor()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

7 private and internal fields
MemberWhat it is
private Vector3 centerWorld position of this object at start, the center of the allowed area.
private bool isTrackingWhether the distance check runs.
private float maxDistanceSquaredSquared allowed distance (set in the inspector as a plain distance).
private Transform targetWhere the player is sent back to. Defaults to this object.
private PlayerController trackingControllerLocal player controller being watched.
private Transform trackingTransformTransform of the watched player controller.
private IUnityUpdateMethod updatePositionRegistered late update handle for UpdatePosition.

Methods​

MemberWhat it is
void SetTracking(bool isEnabled)Turns the distance check on or off.
6 private and internal methods
MemberWhat it is
private void Clear()Stops tracking and forgets the player controller.
private void OnDestroy()Clears tracking and unhooks from LocalPlayerSet.
private void OnDrawGizmosSelected()Draws the allowed radius and the return point in the editor.
private void Start()Hooks LocalPlayerSet, starts tracking the current player if enabled, and stores the center.
private void UpdateLocalPlayer(PlayerController player)Switches tracking to a new local player controller, or clears it when null.
private void UpdatePosition()Late update: if the player's local position is beyond the radius, moves them to target.