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- Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as operator from "operator.operator"
- Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged
Functions
lerp(2 overloads)angle_between(v1:Vector3, v2:Vector3): numberproject_on_plane(plane_normal:Vector3, v:Vector3):Vector3quat_from_euler(euler:Vector3):Quaternioneuler_from_quat(quat:Quaternion):Vector3normalized_target_angle(original: number, target: number): numbernormalized_target_euler(original:Vector3, target:Vector3):Vector3clamp_angle(angle: number, min: number, max: number): numberEASING_INOUT_SINE(x: number): numberEASING_INOUT_CUBIC(x: number): numberEASING_INOUT_QUINT(x: number): numberEASING_INOUT_CIRC(x: number): numberEASING_INOUT_QUAD(x: number): numberEASING_INOUT_QUART(x: number): numberEASING_INOUT_EXPO(x: number): numberget_active_operator():Url| undefinedset_debug(is_debug: boolean)is_debug(): boolean
lerp(2 overloads)
(t: number, a: number, b: number): numberLinearly interpolates from
atob, returninga + (b - a) * t.tis not clamped, so a value outside0to1extrapolates.Parameters
t:number— The progress,0givingaand1givingb.a:number— The start value.b:number— The end value.
Returns
number
(t: number, a: Vector3, b: Vector3): Vector3Linearly interpolates from vector
ato vectorb, returninga + (b - a) * tas a new vector.tis not clamped, so a value outside0to1extrapolates.Parameters
t:number— The progress,0givingaand1givingb.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 thex,yandzaxes, 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, from0to1.
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, from0to1.
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, from0to1.
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, from0to1.
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, from0to1.
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, from0to1.
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, from0to1.
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—trueto 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.