The Disruptibility Behaviour – Let Scenery React on Physical Force

    One day, I was applying a massive magical effect to some spot in a level and it discharged a lot of physical force. But the objects in the surrounding did not react a single bit. That gave the impression that the level is static, dead and uninteresting.

    To cope with that issue, I came up with a new behaviour that would distort the transforms of an object as soon as something happens physcially in the environment, e.g. a magical explosion or a character passing by. That made the scenery overall more realistic – and fun!

    This is, what it looks now: The object’s transforms are modified as following:

    Like this (rotation, slight scaleX) – and leaves are emitted… but that is another behaviour.
    Or stiffer, position on x axis
    Positional shake on y axis
    Explosions have effect, too.
    Combined Disruptibility: rotation => stem; rotation+scale on foilage
    Another type of bush
    Also thinkable: Squeaky constructions with fabrics.

    Editor configuration

    One can distinctly toggle which transform shall be affected by physical force: position, rotation and scale. The affected axis as well; available are X, Y and Z. The configuration of the shake effect is fine-grained. The rigidity in each regard determines how intense the effect amplitude will be, and a limit to the oscillation amplitude can be specified with the amplitude cap value. Sensory input is provided by adding a 2D collider with the isTrigger flag checked.

    Configuring the disruptibility parameters can be a tedious task and always needs a trial-and-error approach.

    Code

    Please note, that the game physics here are simplified and may not correspond with actual physical laws. It just works optically, which is fine for game development. However, the heart of all is the oscillation.

    Data class for an oscillation. Combined with current state (which is represented by the field timer)

    Trigger event methods on the behaviour register and process movement from passing colliders. Axis-specific forces are computed from the by-passing movement force.

    A movement force is determined from the entering collider. This force is then applied.

    If a force is big enough to really result to take effect, an oscillation has to be created. It will be stored and later constantly updated until it is over.

    The applied force is used to generate an oscillation, with the formula you can see here. And there is a typo: “dampening” here means actually “damping”. I won’t re-take the screenshot. The higher the damping, the sooner the oscillation will be over.

    Later on, the oscillation is used to apply an offset to the initial transforms, which are stored when the game object starts its life.

    Here, the position is adjusted. Local mode is a good choice if the object’s parent may move.

    Conclusion

    The feature is not perfect yet, but good enough to breath life into scenery objects. It is ideal to make foilage look more authentic and interactive. That is why I used it for bushes and trees.


    Image sources: Yves Scherdin, Screenshots from UnityEditor and VisualStudio (2025)