Skip to Content
defold-typescript libraries
astrochilidefold-operator

astrochili/defold-operator/operator.operator

Shared settings and math helpers for the Operator camera controller. The camera itself is driven by the properties and messages of operator/operator/operator.script (activate, follow_point, manual_control and the rest), which are not members of this module. The settings fields are plain module fields; assigning one goes through a cast, since a namespace import is read-only: (operator as { flight_look_easing: (this: void, x: number) => number }).flight_look_easing = (x) => x.

  • GitHub: astrochili/defold-operator — pinned to 1.5.3
    1. Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as operator from "operator.operator"

Functions

lerp(2 overloads)

  1. (t: number, a: number, b: number): number

    Linearly interpolates from a to b, returning a + (b - a) * t. t is not clamped, so a value outside 0 to 1 extrapolates.

    Parameters

    • t: number — The progress, 0 giving a and 1 giving b.
    • a: number — The start value.
    • b: number — The end value.

    Returns

    • number
  2. (t: number, a: Vector3, b: Vector3): Vector3

    Linearly interpolates from vector a to vector b, returning a + (b - a) * t as a new vector. t is not clamped, so a value outside 0 to 1 extrapolates.

    Parameters

    • t: number — The progress, 0 giving a and 1 giving b.
    • a: Vector3 — The start vector.
    • b: Vector3 — The end vector.

    Returns

    • Vector3

angle_between(v1: Vector3, v2: Vector3): number

Returns the angle between two vectors, in degrees from 0 to 180. A vector of zero length gives NaN.

Parameters

  • v1: Vector3 — The first vector.
  • v2: Vector3 — The second vector.

Returns

  • number

project_on_plane(plane_normal: Vector3, v: Vector3): Vector3

Projects a vector onto the plane through the origin with the given normal, returning v - plane_normal * vmath.dot(plane_normal, v). The normal must have unit length for the result to lie on the plane.

Parameters

  • plane_normal: Vector3 — The plane's normal, of unit length.
  • v: Vector3 — The vector to project.

Returns

  • Vector3

quat_from_euler(euler: Vector3): Quaternion

Converts Euler angles in degrees to a rotation, composed as z * y * x from the rotations about each axis.

Parameters

  • euler: Vector3 — The angles about the x, y and z axes, in degrees.

Returns

  • Quaternion

euler_from_quat(quat: Quaternion): Vector3

Converts a rotation to Euler angles in degrees, about the x, y and z axes. It reads them back in the order y * x * z, so it reverses quat_from_euler when the z angle is 0. At an x angle near 90 or -90 degrees the z angle is 0.

Parameters

  • quat: Quaternion — The rotation.

Returns

  • Vector3

normalized_target_angle(original: number, target: number): number

Returns target, shifted by one full turn when that makes the turn from original no more than 180 degrees, so an animation from original takes the short way round.

Parameters

  • original: number — The current angle, in degrees.
  • target: number — The wanted angle, in degrees.

Returns

  • number

normalized_target_euler(original: Vector3, target: Vector3): Vector3

Applies normalized_target_angle to each of the x, y and z angles, returning a new vector.

Parameters

  • original: Vector3 — The current Euler angles, in degrees.
  • target: Vector3 — The wanted Euler angles, in degrees.

Returns

  • Vector3

clamp_angle(angle: number, min: number, max: number): number

Brings an angle beyond 360 or -360 degrees back by one full turn, then clamps it between min and max.

Parameters

  • angle: number — The angle, in degrees.
  • min: number — The smallest angle returned, in degrees.
  • max: number — The largest angle returned, in degrees.

Returns

  • number

EASING_INOUT_SINE(x: number): number

Sine ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_CUBIC(x: number): number

Cubic ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_QUINT(x: number): number

Quintic ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_CIRC(x: number): number

Circular ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_QUAD(x: number): number

Quadratic ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1. It is the default flight_look_easing.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_QUART(x: number): number

Quartic ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

EASING_INOUT_EXPO(x: number): number

Exponential ease-in-out: maps a progress from 0 to 1 to an eased progress from 0 to 1.

Parameters

  • x: number — The progress, from 0 to 1.

Returns

  • number

get_active_operator(): Url | undefined

Returns the url of the active operator's game object, or undefined when no operator is active.

Returns

  • Url | undefined

set_debug(is_debug: boolean)

Turns debug mode on or off for every operator and checkpoint: on, they show their camera and checkpoint meshes and draw the active bezier path.

Parameters

  • is_debug: boolean — true to turn debug mode on.

is_debug(): boolean

Returns whether debug mode is on. Starts false.

Returns

  • boolean

Variables

camera_collisions_groups: Hash[]

The collision groups tested by the raycast from the operator anchor to the camera, so the camera stays in front of obstacles. Read on every raycast. Starts as [hash("default")].

flight_bezier_samples_count: number

The number of bezier segments an operator samples a flight path with, which sets how accurate its uniform position is. Read each time an operator starts flying to the next motion point. 16 is usually enough; starts at 32.

flight_look_easing: (x: number) => number

The easing function that turns the camera between motion points, taking the progress from 0 to 1 and returning the eased progress. Starts as EASING_INOUT_QUAD; any of the EASING_INOUT_* functions, or a project's own, can replace it.

On this page