Options
All
  • Public
  • Public/Protected
  • All
Menu

An object in the game that players can interact with

Hierarchy

Index

Properties

onCreated

onCreated: MulticastDelegate<(object: this) => void>

Called when the object is created (from the object library, loading a game, copy & paste, dragging from an infinite container or stack...)

param

The new object

onDestroyed

onDestroyed: MulticastDelegate<(object: this) => void>

Called when the object is destroyed

param

The destroyed object

onGrab

onGrab: MulticastDelegate<(object: this, player: Player) => void>

Called when the object is picked up

param

The object being grabbed

param

The player that grabbed the object

onHit

onHit: MulticastDelegate<(object: this, otherObject: GameObject, first: boolean, impactPoint: Vector, impulse: Vector) => void>

Called when the object is hit by another object or hits another object. Gets called for both objects involved in a collision. Only called for collisions that cause an impact sound to be played.

param

The first object in the collision

param

The second object in the collision. Can be undefined if an object collides with scenery.

param

True if this call is the first of the two calls made for each collision. Check this parameter if you only want to react once to a collision but both colliding objects can have the onHit event defined.

param

The position at which the two objects collided

param

Direction and magnitude of the impulse generated by the collision on the first object. Invert to get impulse on the second object.

onMovementStopped

onMovementStopped: MulticastDelegate<(object: this) => void>

Called when the object comes to rest. For ground objects or when the session is set to locked physics, the object has been locked right before this event is triggered.

onNumberAction

onNumberAction: MulticastDelegate<(object: this, player: Player, number: number) => void>

Called a player executes a number action on the object (by highlighting or selecting it and pressing number keys). Will be called even if the object has a defined behavior for number actions (like dice or multistate objects), after any object defined behavior.

param

The object on which the action is executed

param

The player that executed the action

onPrimaryAction

onPrimaryAction: MulticastDelegate<(object: this, player: Player) => void>

Called a player executes the primary action on an object by pressing the respective button (default mapping "R"). Will be called even if the object has a defined behavior for primary actions (like dice or multistate objects), after any object defined primary action.

param

The object on which the action is executed

param

The player that executed the action

onReleased

onReleased: MulticastDelegate<(object: this, player: Player, thrown: boolean, grabPosition: Vector, grabRotation: Rotator) => void>

Called when the object is released (but not snapped or reset).

param

The object being released

param

The player that released the object

param

True if the object was thrown (released above a threshold velocity) instead of being dropped

param

The position where this object was when it was grabbed. Zero if it hasn't been grabbed (for example when it was dragged from the object library).

param

The rotation this object had when it was grabbed.

onReset

onReset: MulticastDelegate<(object: this, player: Player) => void>

Called when the object is reset to its position before being picked up.

param

The object being reset

param

The player that reset the object

onSecondaryAction

onSecondaryAction: MulticastDelegate<(object: this, player: Player) => void>

Called a player executes the secondary action on an object by pressing the respective button (default mapping "Ctrl+R"). Will be called even if the object has a defined behavior for primary actions (like card stacks or multistate objects), after any object defined primary action.

param

The object on which the action is executed

param

The player that executed the action

onSnapped

onSnapped: MulticastDelegate<(object: this, player: Player, snapPoint: SnapPoint, grabPosition: Vector, grabRotation: Rotator) => void>

Called when the object is snapped on releasing.

param

The object being released

param

The player that released the object

param

The point that the object is moved to

param

The position where this object was when it was grabbed. Zero if it hasn't been grabbed (for example when it was dragged from the object library)

param

The rotation this object had when it was grabbed.

onTick

onTick: MulticastDelegate<(object: this, deltaTime: number) => void>

Called every tick.

param

The reference object

param

Duration of the previous tick

Methods

applyAngularImpulse

  • applyAngularImpulse(impulse: Vector, useMass?: boolean): void
  • Apply a torque to the object. Works as an instant change of angular velocity.

    Parameters

    • impulse: Vector

      The axis of rotation and magnitude of the impulse to apply in kg*cm^2/s.

    • Optional useMass: boolean

      If false (default), ignore the mass of the object and apply the force directly as change of angular velocity in cm^2/s.

    Returns void

applyForce

  • applyForce(force: Vector, useMass?: boolean): void
  • Apply a force to the object. Works like 'thruster' and should be called every tick for the duration of the force.

    Parameters

    • force: Vector

      The direction and magnitude of the force to apply in kg*cm/s^2.

    • Optional useMass: boolean

      If false (default), ignore the mass of the object and apply the force directly as change of acceleration in cm/s^2.

    Returns void

applyForceAtPosition

  • applyForceAtPosition(force: Vector, position: Vector): void
  • Apply a force to the object. Works like 'thruster' and should be called every tick for the duration of the force.

    Parameters

    • force: Vector

      The direction and magnitude of the force to apply in kg*cm\s^2.

    • position: Vector

      The position where to apply the force, relative to the object origin. If this is not equal to the center of mass, the force will create angular acceleration.

    Returns void

applyImpulse

  • applyImpulse(impulse: Vector, useMass?: boolean): void
  • Apply an impulse to the object. Works as an instant change of velocity.

    Parameters

    • impulse: Vector

      The direction and magnitude of the impulse to apply in kg*cm/s.

    • Optional useMass: boolean

      If false (default), ignore the mass of the object and apply the impulse directly as change of velocity in cm/s.

    Returns void

applyImpulseAtPosition

  • applyImpulseAtPosition(impulse: Vector, position: Vector): void
  • Apply an impulse to the object. Works as an instant change of velocity.

    Parameters

    • impulse: Vector

      The direction and magnitude of the impulse to apply in kg*cm/s

    • position: Vector

      The position where to apply the impulse, relative to the object origin. If this is not equal to the center of mass, the force will create angular velocity.

    Returns void

applyTorque

  • applyTorque(torque: Vector, useMass?: boolean): void
  • Apply a torque to the object. Works like 'thruster' and should be called every tick for the duration of the torque.

    Parameters

    • torque: Vector

      The axis of rotation and magnitude of the torque to apply in kg*cm^2/s^2.

    • Optional useMass: boolean

      If false (default), ignore the mass of the object and apply the force directly as change of angular acceleration in cm^2/s^2.

    Returns void

attachUI

  • Attach a new UI element object to this object.

    Parameters

    • element: UIElement

      The UI element to attach

    Returns void

destroy

  • destroy(): void

getAllSnapPoints

getAngularVelocity

getAttachedUIs

  • Get an array of all attached UI elements. Modifying the array won't change the actual UIs, use setUI to update.

    Returns UIElement[]

getBounciness

  • getBounciness(): number
  • Return the object's bounciness value

    Returns number

getCenterOfMass

getContainer

  • Returned the container that this object is in. Return undefined if the object is not in a container.

    Returns Container

getDensity

  • getDensity(): number
  • Return the object's density value

    Returns number

getDescription

  • getDescription(): string
  • Return the object's description

    Returns string

getExecutionReason

  • getExecutionReason(): string
  • Used when executing an object script to determine why it was executed. Possible return values:
    "Create" - The object was newly created, for example from the object library or through copy and paste
    "ScriptReload" - The script was reloaded, for example because it was set on the object for the first time, or because the scripting environment was reset
    "StateLoad" - A game state that contained the object was loaded

    Returns string

getExtent

  • getExtent(currentRotation: boolean): Vector
  • Get the object extent: half-size of an axis-aligned bounding box encompassing the object. Adding this vector to the position returned by GetExtentCenter gives a corner of the bounding box.

    Parameters

    • currentRotation: boolean

      If true, return the extent of an axis-aligned bounding box around the object at its current rotation. If false, return for the default rotation.

    Returns Vector

getExtentCenter

  • getExtentCenter(currentRotation: boolean): Vector
  • Get the center of the object extent: an axis-aligned bounding box encompassing the object. This will often be the same position as returned by GetPosition, but will differ for objects with their physical center not at their volume center.

    Parameters

    • currentRotation: boolean

      If true, return the extent of an axis-aligned bounding box around the object at its current rotation. If false, return for the default rotation.

    Returns Vector

getFriction

  • getFriction(): number
  • Return the object's friction value

    Returns number

getGroupId

  • getGroupId(): number
  • Return the object's group id. Objects with the same group id are always picked up together. Returns -1 if the object is not part of a group.

    Returns number

getId

  • getId(): string

getLinearVelocity

getMass

  • getMass(): number

getMetallic

  • getMetallic(): number
  • Return the object's metallic value.

    Returns number

getName

  • getName(): string
  • Return the object's user visible name

    Returns string

getObjectType

  • getObjectType(): number
  • Get the object's type. Possible values are defined in ObjectType:
    0: Regular
    1: Ground
    2: Penetrable

    Returns number

getPackageId

  • getPackageId(): string
  • Return the id of the package that the object's template belongs to

    Returns string

getPackageName

  • getPackageName(): string
  • Return the name of the package that the object's template belongs to

    Returns string

getPosition

getPrimaryColor

  • getPrimaryColor(): Color

getRotation

getRoughness

  • getRoughness(): number
  • Return the object's roughness value. Lower roughness makes the object more shiny.

    Returns number

getSavedData

  • getSavedData(): string

getScale

getSecondaryColor

  • getSecondaryColor(): Color

getSnapPoint

  • Return a snap point of the object

    Parameters

    • index: number

      Index of the snap point

    Returns SnapPoint

getSurfaceType

  • getSurfaceType(): string
  • Return surface type. Only affects sound effects when colliding with other objects.

    Returns string

getTemplateId

  • getTemplateId(): string
  • Return the object's template id

    Returns string

getTemplateName

  • getTemplateName(): string
  • Return the name of the object's template

    Returns string

isHeld

  • isHeld(): boolean
  • Return if the object is currently held by a player

    Returns boolean

isSimulatingPhysics

  • isSimulatingPhysics(): boolean
  • Return whether the object is currently simulating physics. If false, the object is stuck in place and won't move when hit by other objects. This can happen with stationary ground mode objects or with locked physics sessions.

    Returns boolean

isSnappingAllowed

  • isSnappingAllowed(): boolean
  • Return whether the object is allowed to snap

    Returns boolean

isValid

  • isValid(): boolean
  • Return whether the object is valid. An object becomes invalid after it has been destroyed

    Returns boolean

localPositionToWorld

  • Transform an object position to a world position

    Parameters

    • position: Vector

      The position relative to the object center to transform to world space

    Returns Vector

localRotationToWorld

  • Transform an object rotation to a world rotation

    Parameters

    • rotation: Rotator

      The rotation relative to the object center to transform to world space

    Returns Rotator

removeUI

  • removeUI(index: number): void
  • Remove an attached UI element.

    Parameters

    • index: number

      The index of the UI element to remove

    Returns void

setAngularVelocity

  • setAngularVelocity(velocity: Rotator): void
  • Set the object's angular (rotational) velocity in degrees/second. Note that setting velocity directly can lead make the physics simulation unstable, you should prefer to apply impulse, torque, or force to the object.

    Parameters

    • velocity: Rotator

      The new angular velocity

    Returns void

setBounciness

  • setBounciness(bounciness: number): void
  • Set the object's bounciness value

    Parameters

    • bounciness: number

      The new bounciness value, from 0 to 1

    Returns void

setDensity

  • setDensity(density: number): void
  • Set the object's density value

    Parameters

    • density: number

      The new density value

    Returns void

setDescription

  • setDescription(description: string): void
  • Set the object's description

    Parameters

    • description: string

      The new object description. Maximum length is 1023 characters

    Returns void

setFriction

  • setFriction(friction: number): void
  • Set the object's friction value

    Parameters

    • friction: number

      The new friction value, from 0 to 1

    Returns void

setGroupId

  • setGroupId(groupID: number): void
  • Set the object's group id. Objects with the same group id are always picked up together.

    Parameters

    • groupID: number

    Returns void

setId

  • setId(iD: string): boolean
  • Set the object's unique id. Returns whether the Id was changed successfully.

    Parameters

    • iD: string

    Returns boolean

setLinearVelocity

  • setLinearVelocity(velocity: Vector): void
  • Set the object's linear velocity in cm/second. Note that setting velocity directly can lead make the physics simulation unstable, you should prefer to apply impulese or force to the object.

    Parameters

    • velocity: Vector

      The new velocity

    Returns void

setMetallic

  • setMetallic(metallic: number): void
  • Set the object's metallic value

    Parameters

    • metallic: number

      The new metallic value, from 0 to 1

    Returns void

setName

  • setName(name: string): void
  • Set the object's user visible name

    Parameters

    • name: string

      The new name

    Returns void

setObjectType

  • setObjectType(type: number): void
  • Set the object's type. Available options are defined in ObjectType:
    0: Regular
    1: Ground
    2: Penetrable

    Parameters

    • type: number

      The new object type

    Returns void

setPosition

  • setPosition(position: Vector, animationSpeed: number): void
  • Set the object's position. Optionally show an animation of the object flying toward the new location. The animation is only visual, the physical location of the object is changed instantly. Does not have an effect if a player is currently holding the object.

    Parameters

    • position: Vector

      The new position

    • animationSpeed: number

      If larger than 0, show animation. A value of 1 gives a reasonable, quick animation. Value range clamped to [0.1, 5.0].

    Returns void

setPrimaryColor

  • setPrimaryColor(color: Color): void
  • Set the object's primary color

    Parameters

    • color: Color

      The new primary color

    Returns void

setRotation

  • setRotation(rotation: Rotator, animationSpeed: number): void
  • Set the object's rotation. Optionally show an animation of the object rotating toward the new orientation. The animation is only visual, the physical rotation of the object is changed instantly. Does not have an effect if a player is currently holding the object.

    Parameters

    • rotation: Rotator

      The new rotation

    • animationSpeed: number

      If larger than 0, show animation. A value of 1 gives a reasonable, quick animation. Value range clamped to [0.1, 5.0].

    Returns void

setRoughness

  • setRoughness(roughness: number): void
  • Set the object's roughness value. Lower roughness makes the object more shiny.

    Parameters

    • roughness: number

      The new roughness value, from 0 to 1

    Returns void

setSavedData

  • setSavedData(data: string): void
  • Set the data that will stored in save game states. The data is available using getSavedData when the object script is run after loading a save state. Try to keep this data small and don't change it frequently, it needs to be sent over the network to all clients.

    Parameters

    • data: string

      Data to store, maximum length 1023 characters

    Returns void

setScale

  • setScale(scale: Vector): void
  • Set the object's scale instantly

    Parameters

    Returns void

setSecondaryColor

  • setSecondaryColor(color: Color): void
  • Set the object's secondary color

    Parameters

    • color: Color

      The new secondary color

    Returns void

setSnappingAllowed

  • setSnappingAllowed(allowed: boolean): void
  • Set whether the object is allowed to snap

    Parameters

    • allowed: boolean

      Whether snapping will be allowed

    Returns void

setSurfaceType

  • setSurfaceType(surfaceType: string): void
  • Set surface type. Only affects sound effects when colliding with other objects.

    Parameters

    • surfaceType: string

    Returns void

setUI

  • setUI(index: number, element: UIElement): void
  • Replace an attached UI element. Will not do anything if called with an index that doesn't have a UI element. You can also use this function when you update an UIElement (for example by changing the position or size), simply set it to its previous index.

    Parameters

    Returns void

snap

  • Snap the object as if it was dropped at its current position. Does nothing if no snap point is in range below the object. Snapping in this way does not trigger the onSnapped callback. Returns the snapped point if the object was snapped.

    Returns SnapPoint

snapToGround

  • snapToGround(): void
  • Snap the object to the ground below it.

    Returns void

toJSONString

  • toJSONString(): string
  • Return a Json string representing the object. Can be used to spawn copies.

    Returns string

toggleLock

  • toggleLock(): void
  • Immediately freeze the object and set its type to ground if it is currently not a ground object. Set its to regular if it is currently a ground object.

    Returns void

worldPositionToLocal

  • Tranform a world position to an object position

    Parameters

    • position: Vector

      The position in world space to transform to relative to the object

    Returns Vector

worldRotationToLocal

  • Tranform a world rotation to an object rotation

    Parameters

    • rotation: Rotator

      The rotation in world space to transform to relative to the object

    Returns Rotator