Breakables and Constant Velocity

A few small components round out the Toolkit: breakable objects with a clean destroy sequence, and components that hold a Rigidbody at a constant velocity.

Breakable #

Breakable swaps an intact object for a broken one, for example a whole vase for a pile of shards, when it takes a hard enough impact or when you call Break(). Put it on the object, assign the intact and broken GameObjects, and set what should happen next.

SettingDefaultWhat it does
unbrokennoneThe intact version, deactivated on break.
brokennoneThe broken version, activated on break.
parentRigidbodynoneAn optional Rigidbody to freeze when the object breaks.
breakForce0The relative speed of impact, in metres per second, that breaks the object. Zero disables impact breaking.
addForce0A force added at the point of impact when breaking. Zero disables it.
addForceRadius0The radius of that force. Zero disables it.
disableTimer0Seconds after the break before the child Rigidbodies are disabled. Zero disables it.
destroyTimer0Seconds after the break before the object is destroyed. Zero disables it.
eventOnlyoffWhen on, a sufficient impact fires the Collision Break event but does not call Break(), so you can sync the break with a networking API.

Events: collisionBreak (an impact was hard enough), breaking (the object broke), physicsDisabled (the pieces had their physics disabled) and destroying (the object is about to be destroyed). IsBroken is true once it has broken, and Break() breaks it now if it has not already. Breakable handles a missing intact object, broken object or events without error.

Destroy effects #

To replace the default destruction with something nicer, put a component implementing IDestroyEffect next to the Breakable. SinkingDestroy is the included one: it sinks the object before destroying it, good for wreckage.

SinkingDestroy settingDefaultWhat it does
direction(0, -1, 0)The direction the object sinks in.
speed0.25The speed it sinks at, in metres per second.
duration5How long it sinks, in seconds, before it is destroyed.

IsDestroying is true while it is sinking.

Constant velocity #

ConstantLinearVelocity and ConstantAngularVelocity hold a Rigidbody at a velocity by applying the force or torque needed to keep it there every fixed step. Set targetRelativeVelocity to the world-space velocity to hold: metres per second for linear, radians per second for angular. They are good for conveyors, spinning platforms and steady-speed movers.

Rate This Article!