Skip to main content

SafePositionSetter

A class in Root.Township, the global namespace.

A networked marker that, when triggered, sets a player's fall-recovery safe position to its target point. Only one is current per client; becoming current or not fires events and animates a 0 to 1 progress.

Constructors​

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

Fields​

11 private and internal fields
MemberWhat it is
private float animationDurationSeconds the progress animation takes. Default 2.
private FloatEvent animationUpdateFloat event fired with the progress value during the animation.
private static SafePositionSetter currentSafePositionSetterThe setter that last set the local player's safe position, if still active.
private AltaEvent onBecameActiveEvent fired when this becomes the current setter.
private AltaEvent onBecameInactiveEvent fired when this stops being the current setter.
private float progressCurrent animation progress from 0 to 1.
private Coroutine progressAnimationThe running Animate coroutine, if any.
private MethodSync syncActivatedMethod sync the server uses to tell a client to apply the safe position.
private MethodSync syncPositionMethod sync for the target's offset.
private Transform targetTransform marking the safe position. Its local position is saved and synced.
private float targetProgressProgress the animation is heading to: 1 when current, 0 when not.

Methods​

MemberWhat it is
override void Initialize()Creates the activation and position method syncs.
override void OnConnected(Player player)Server: sends the target's offset to a joining player.
void SetSafePosition(IPlayer player)For a remote player the server tells their client to run it. For the local player, sets their smooth locomotion safe position to the target if the chunk allows it.
7 private and internal methods
MemberWhat it is
private IEnumerator Animate() (iterator)Client: coroutine that moves progress toward targetProgress over animationDuration and fires animationUpdate each frame.
private void CheckForDisable(LocationChunk obj)When the local player changes chunk and the chunk no longer overrides the safe position, makes this setter inactive.
private void OnDestroy()If this is the current setter, marks it inactive and clears the static current setter.
private void OnDrawGizmos()Editor: draws a line and sphere to the target point.
private void SyncActivated(IPlayer player, Stream stream)Client: on receiving the activation message, sets the safe position for the local player.
private void SyncPosition(IPlayer player, Stream stream)Syncs the target's local position, within 10 units on each axis.
private void UpdateAsCurrent(bool isCurrent, bool withAnimation = true)Makes this the current setter or clears it, fires the matching event and starts the progress animation.