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.
- Listed in Global namespace: P
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
PlayerPositionRestrictor() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private Vector3 center | World position of this object at start, the center of the allowed area. |
private bool isTracking | Whether the distance check runs. |
private float maxDistanceSquared | Squared allowed distance (set in the inspector as a plain distance). |
private Transform target | Where the player is sent back to. Defaults to this object. |
private PlayerController trackingController | Local player controller being watched. |
private Transform trackingTransform | Transform of the watched player controller. |
private IUnityUpdateMethod updatePosition | Registered late update handle for UpdatePosition. |
Methods
| Member | What it is |
|---|---|
void SetTracking(bool isEnabled) | Turns the distance check on or off. |
6 private and internal methods
| Member | What 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. |