Skip to main content

BreakOnImpact

A class in Root.Township, the global namespace.

Server checks collisions on a networked object: a fast enough hit plays a hit effect, a faster one breaks it and runs the server break event. Effects are synced to nearby clients.

Constructors​

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

Fields​

MemberWhat it is
protected float breakVelocitySquaredSquared relative speed needed to break (64, so 8 m/s).
10 private and internal fields
MemberWhat it is
private float hitVelocitySquaredSquared relative speed needed for a hit effect (16, so 4 m/s).
private bool isAlignedWithHitNormalIf true, effects face the contact normal and their position is sent; otherwise they use the object's transform.
private float lastSafetyLockTime the safety lock last started.
private BreakOnImpact.TransformProxyEvent onClientBreakBreak effect event. Not run on a headless server.
private UnityEvent onHitHit effect event. Not run on a headless server.
private BreakOnImpact.TransformProxyEvent onServerBreakServer event when the object breaks, for the gameplay result.
private float safetyLockDurationSeconds after a grab or teleport during which it can't break (0.5 by default).
private MethodSyncClass<TransformProxy> syncBreakingNetwork sync for break effects.
private MethodSyncClass<TransformProxy> syncHittingNetwork sync for hit effects.
private HashSet<PlayerController> trackedPlayersPlayers whose teleports are being watched.

Properties​

MemberWhat it is
BreakOnImpact.TransformProxyEvent OnBreak { get; set; }The client break event (onClientBreak), with where the effect should play.

Methods​

MemberWhat it is
override void Initialize()Starts the safety lock and creates the break and hit sync messages.
override void InitializeAsServer(SpawnData spawnData)Server: for a pickup, tracks grabs so grabbing and teleporting reset the safety lock.
protected virtual void OnCollisionEnter(Collision collision)Server: after the safety lock, compares relative speed to the hit and break thresholds and fires and syncs the matching events.
9 private and internal methods
MemberWhat it is
private void EndInteraction(Interactable interactable, Interactor interactor)Stops listening to the player's teleports when they let go. It never removes them from trackedPlayers, so later grabs by the same player don't resubscribe.
private void Alta.Impact.IToolHitDependant.OnCollided(Collision collision, bool isHitting, ImpactTool tool)Tool hit callback: passes the collision on if one of its contacts belongs to this object.
private void Alta.Impact.IToolHitDependant.OnHit(ImpactHitWithTool hit, ImpactTool tool)Tool hit callback; does nothing.
private void ResetSafetyLock()Restarts the safety lock timer, during which no break can happen.
private void ResetTeleport(PlayerController player, Vector3 oldPosition, Vector3 newPosition, LocomotionFunction function)Resets the safety lock when a holding player recovers, repositions or teleports.
private void StartInteraction(Interactable interactable, Interactor interactor)Resets the safety lock on grab and starts watching the player's teleports.
private void SyncBreaking(IPlayer player, Stream stream, TransformProxy proxy)Message handler for a break effect.
private void SyncEffect(Stream stream, TransformProxy proxy, bool isBreak)Reads the effect position (only sent when aligned with the hit normal) and plays the break or hit event on clients.
private void SyncHitting(IPlayer player, Stream stream, TransformProxy proxy)Message handler for a hit effect.