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.
- Listed in Global namespace: A to B
- Inherits or implements
NetworkEntityBehaviour,IToolHitDependant - Derived types
PickupBreakOnImpact - Nested types
TransformProxyEvent,TransformProxyHandler
Constructors
| Member | What it is |
|---|---|
BreakOnImpact() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected float breakVelocitySquared | Squared relative speed needed to break (64, so 8 m/s). |
10 private and internal fields
| Member | What it is |
|---|---|
private float hitVelocitySquared | Squared relative speed needed for a hit effect (16, so 4 m/s). |
private bool isAlignedWithHitNormal | If true, effects face the contact normal and their position is sent; otherwise they use the object's transform. |
private float lastSafetyLock | Time the safety lock last started. |
private BreakOnImpact.TransformProxyEvent onClientBreak | Break effect event. Not run on a headless server. |
private UnityEvent onHit | Hit effect event. Not run on a headless server. |
private BreakOnImpact.TransformProxyEvent onServerBreak | Server event when the object breaks, for the gameplay result. |
private float safetyLockDuration | Seconds after a grab or teleport during which it can't break (0.5 by default). |
private MethodSyncClass<TransformProxy> syncBreaking | Network sync for break effects. |
private MethodSyncClass<TransformProxy> syncHitting | Network sync for hit effects. |
private HashSet<PlayerController> trackedPlayers | Players whose teleports are being watched. |
Properties
| Member | What it is |
|---|---|
BreakOnImpact.TransformProxyEvent OnBreak { get; set; } | The client break event (onClientBreak), with where the effect should play. |
Methods
| Member | What 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
| Member | What 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. |