Beep8 logo

Game Math Documentation

Game Math Documentation Source Code

A handy collection of mathematical functions and constants for game development.

Math Methods

beep8.Math.dist2D(x0, y0, x1, y1)

Calculates a 2D distance between points (x0, y0) and (x1, y1).

Parameters

  • x0 (number): The x-coordinate of the first point.
  • y0 (number): The y-coordinate of the first point.
  • x1 (number): The x-coordinate of the second point.
  • y1 (number): The y-coordinate of the second point.

Returns

  • (number): The distance between the two points.

beep8.Math.fade(t)

A smoothing function for interpolation.

This is Perlin’s classic fade function 6t^5 - 15t^4 + 10t^3. It eases coordinate values so that they will ease towards integral values. This ends up smoothing the final output.

Parameters

  • t (number): The interpolation factor (0.0 to 1.0).

Returns

  • (number): The smoothed interpolation factor.

beep8.Math.lerp(a, b, t)

Linearly interpolates between two values.

Parameters

  • a (number): The start value.
  • b (number): The end value.
  • t (number): The interpolation factor (0.0 to 1.0).

Returns

  • (number): The interpolated value.

beep8.Math.smoothstep(t)

A simpler smoothing function for interpolation.

This is the smoothstep function 3t^2 - 2t^3. It eases coordinate values so that they will ease towards integral values. This ends up smoothing the final output.

Parameters

  • t (number): The interpolation factor (0.0 to 1.0).

Returns

  • (number): The smoothed interpolation factor.

More Beep8 Docs

Actors Documentation

App Intro Documentation

Async Documentation

Cart API

Core Functions

ECS (Entity Component System) Documentation

Game Math Documentation

Game State

Input Documentation

Inventory API

Joystick Documentation

Menu Documentation

Music Documentation

Particle System Documentation

Passcodes Documentation

Public API

Random Numbers Documentation

SFX Documentation

Scene Documentation

Text Renderer

Textmode

Tilemap Documentation

Utilities Documentation