Strata - v1.4.10
    Preparing search index...

    Function calculateHeadBob

    • Calculate procedural head bob offset for first-person cameras.

      Generates vertical and horizontal oscillation based on walking speed. Creates a sense of footsteps and physical presence.

      Parameters

      • time: number

        Accumulated time (grows each frame)

      • speed: number

        Current movement speed (units/sec)

      • bobFrequency: number = 10

        Oscillation frequency in Hz. Default: 10

      • bobAmplitude: number = 0.05

        Maximum displacement. Default: 0.05

      Returns Vector3

      Head bob offset vector

      let bobTime = 0;
      const movementSpeed = 5.0;
      const isMoving = true;

      if (isMoving) {
      bobTime += deltaTime * movementSpeed;
      const bob = calculateHeadBob(bobTime, movementSpeed, 12, 0.04);
      camera.position.add(bob);
      }