ixfx
    Preparing search index...

    Function constrainBounce

    • constrainBounce yields a function that affects t's position and velocity such that it bounces within bounds.

      // Setup bounce with area constraints
      // Reduce velocity by 10% with each impact
      const b = constrainBounce({ width:200, height:500 }, 0.9);

      // Thing
      const t = {
      position: { x: 50, y: 50 },
      velocity: { x: 0.3, y: 0.01 }
      };

      // `b` returns an altereted version of `t`, with the
      // bounce logic applied.
      const bounced = b(t);

      dampen parameter allows velocity to be dampened with each bounce. A value of 0.9 for example reduces velocity by 10%. A value of 1.1 will increase velocity by 10% with each bounce.

      Parameters

      • Optionalbounds: Geometry.Rect

        Constraints of area

      • dampen: number = 1

        How much to dampen velocity by. Defaults to 1 meaning there is no damping.

      Returns (t: ForceAffected) => ForceAffected

      A function that can perform bounce logic