Skip to main content

BobbingController

A class in Root.Township, the global namespace.

Makes a list of child objects bob back and forth and slowly spin, each with its own random offset. Runs in edit mode too.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private float bobbingSpeedBacking field for BobbingSpeed.
private float bobbingStrengthBacking field for BobbingStrength.
private bool isSettingUpInspector Setup button.
private float movementRadiusRadius objects are scattered in by AddObjectToBob.
private List<Transform> objectsToBobTransforms being bobbed.
private List<float> randomOffsetsSine phase per object.
private List<Vector3> randomRotationAxisSpin axis per object.
private List<float> randomRotationsSpeedSpin speed per object, 0.1 to 1.
private float rotationSpeedOverall spin speed multiplier.

Properties​

MemberWhat it is
float BobbingSpeed { get; set; }How fast objects bob. Read and write.
float BobbingStrength { get; set; }How far objects bob along local Z. Read and write.

Methods​

MemberWhat it is
void AddObjectToBob(Transform objectToBob)Adds an object, puts it at a random spot within movementRadius with a random rotation, and turns bobbing on.
void ClearObjects()Removes all objects and offsets and turns the component off.
6 private and internal methods
MemberWhat it is
private void Awake()Turns itself off if there is nothing to bob and sets up the random offsets.
private void CreateNewRandomOffsets()Adds a random phase, spin axis and spin speed for one object.
private void OnDrawGizmosSelected()Editor: draws movementRadius as a wire sphere.
private void OnValidate()Editor: rebuilds offsets when the Setup button is pressed.
private void SetupOffsets()Rebuilds the random offsets for every object in the list.
private void Update()Moves each object's local Z on a sine wave and spins it. Drops destroyed objects and turns off when empty.

Used in​

Members of other types that take, return or hold a BobbingController: