attribute() – API Reference

By |

ATTRIBUTE( NAME )

Returns the value of an attribute.

name – Name of the attribute.

function init(){
  let speed = this.attribute('Speed');
}

Animation – API Reference

By |

Animation

This kind of Animation can be created from an Animation script attribute. It’s useful because you can instantiate many copies of the same animation attribute using code. An Animation is two-dimensional. Here’s an example of creating an Animation from an attribute.

    let attribute = this.attribute('Flame');
    let anim = new Animation(attribute, this);
Function Description
play()

Starts playing the animation from its beginning.

position()

Returns the Animation’s position relative to its Entity.

rotation()

Returns the rotation of the Animation. in degrees.

scale()

Returns the scale of the Animation.

setFrame(value)

Sets the Animation to a specific frame.

setOpacity(value)

Sets the opacity of the Animation.

setPosition(x, y, z)

Sets the position of the Animation.

setRotation(value)

Sets the rotation of the Animation, in degrees.

setScale(x, y, z)

Sets the scale of the Animation.

setVisible(value)

Sets the visibility of the Animation.


play()

Starts playing the animation from its beginning.

↑ Back to top


position()

Returns the Animation’s position relative to its Entity.

Returns

Vec3 {x, y} relative coordinates of the Animation.

↑ Back to top


rotation()

Returns the rotation of the Animation. in degrees.

Returns

number the rotation of the Animation, in degrees.

↑ Back to top


scale()

Returns the scale of the Animation.

Returns

Vec2 {x, y} scale of the Animation.

↑ Back to top


setFrame(value)

Sets the Animation to a specific frame.

Parameters

number value – the frame the Animation will be set to.

↑ Back to top


setOpacity(value)

Sets the opacity of the Animation.

Parameters

number value – new opacity value, range: 0-255

↑ Back to top


setPosition(x, y, z)

Sets the position of the Animation.

Parameters

number x – new x-axis position of the Animation
number y – new y-axis position of the Animation
number z – (optional) z-axis position of the Animation

↑ Back to top


setRotation(value)

Sets the rotation of the Animation, in degrees.

Parameters

number value – new rotation of the Animation, in degrees

↑ Back to top


setScale(x, y, z)

Sets the scale of the Animation.

Parameters

number x – x-axis scale of the Animation
number y – y-axis scale of the Animation
number z – (optional) z-axis scale of the Animation

↑ Back to top


setVisible(value)

Sets the visibility of the Animation.

Parameters

boolean value – true for visible, false for not visible.

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Ads – API Reference

By |

Ads

These functions help you control advertisements shown in your game. Check out this page of the manual to learn how to monetize your game with advertisements. Note that you won’t see any ad banners or videos in the Preview window of BuildBox.

Static Function Description
hideBanner()

Hides a banner ad if it is visible.

isRemoveAdsPurchased()

Returns true if the user has paid to remove ads, and false if not.

isRewardedVideoAvailable()

Returns true if a rewarded video is available to show, and false if not.

showBanner()

Shows a banner ad.

showInterstitial()

Shows an interstitial (video advertisement) to the user.

showRewardedVideo(callback)

Shows Rewarded Video to the user. callback will be triggered when the video ends.


hideBanner()

Hides a banner ad if it is visible.

↑ Back to top


isRemoveAdsPurchased()

Returns true if the user has paid to remove ads, and false if not. Check this page of the manual to learn how to allow the user to pay to remove ads.

Returns

boolean true if the user has paid to remove ads, false if not

↑ Back to top


isRewardedVideoAvailable()

Returns true if a rewarded video is available to show, and false if not.

Returns

boolean true if a rewarded video is available to show, false if not

↑ Back to top


showBanner()

Shows a banner ad.

↑ Back to top


showInterstitial()

Shows an interstitial (video advertisement) to the user.

↑ Back to top


showRewardedVideo(callback)

Shows Rewarded Video to the user. callback will be triggered when the video ends.

let callback = function(){
    //when this fires, the rewarded video is complete. Give reward to player here 
}
 callback = callback.bind(this);
 Ads.showRewardedVideo(callback);

↑ Back to top

 

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Keyframe Animation Model – API Reference

By |

Keyframe Animation Model

Keyframe Animaion Models are used with Sub Scenes to control FBX assets. Check the manual page for more information.

Function Description
duration()

Returns the duration of the Keyframe Animation Model.

name()

Returns the name of the Keyframe Animation Model.


duration()

Returns the duration of the Keyframe Animation Model.

Returns

number the duration of the animation

↑ Back to top


name()

Returns the name of the Keyframe Animation Model.

Returns

string the name of the animation

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

If Collide – API Reference

By |

If Collide

Function Description
affectedAsset()

Returns the affected asset of the If Collide node. If the entity collides with another entity of the affected asset type, the If Collide node will trigger its “Collide” output signal.

collisionEntity()

Returns the last Entity that was collided with. Returns Null if there has never been a collision.

mesh()

Returns the collision shape mesh, if the If Collide node has one. Returns null if not.

parentEntity()

Returns the entity that the If Collide node belongs to.

rebuildShape()

This method rebuilds the collision shape of the If Collide node. You must call this when you want a new shape position, rotation, scale, and/or type applied. Warning: this is a costly operation.

setActive(value)

Enables/disables the If Collide node.

setAffectedAsset(value)

Changes the affected asset of the If Collide node.

setMesh(meshModel)

Sets the mesh of the collision shape using a MeshModel script attribute. See attribute() in the Script section for more information.

setMesh(value)

Sets the mesh of the collision shape using a string name. It is recommended to use a MeshModel script attribute instead, to avoid issues with meshes with the same name.

setShapePosition(x, y, z)

Sets the position of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

setShapeRotation

Sets the rotation of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

setShapeScale

Sets the scale of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

setShapeType(type)

Sets the collision shape type. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.
It is recommended to use “kHullShape” over “kMeshShape” as it is less memory intensive.

shapePosition()

Returns the position of the collision shape.

shapeRotation()

Returns the rotation of the collision shape.

shapeScale()

Returns the scale of the collision shape.

shapeType()

Returns the type of the collision shape.


affectedAsset()

Returns the affected asset of the If Collide node. If the entity collides with another entity of the affected asset type, the If Collide node will trigger its “Collide” output signal.

Returns

string the affected asset of the If Collide node: kNone, kCharacter, kEnemy, kPlatform, kCoin

↑ Back to top


collisionEntity()

Returns the last Entity that was collided with. Returns Null if there has never been a collision.

Returns

Entity the last Entity that was collided with

↑ Back to top


mesh()

Returns the collision shape mesh, if the If Collide node has one. Returns null if not.

Returns

Mesh Model the collision shape mesh

↑ Back to top


parentEntity()

Returns the entity that the If Collide node belongs to.

Returns

Entity the If Collide’s parent Entity

↑ Back to top


rebuildShape()

This method rebuilds the collision shape of the If Collide node. You must call this when you want a new shape position, rotation, scale, and/or type applied. Warning: this is a costly operation.

    let col = this.entity().component("If Collide");
    col.setShapePosition(0, 1, 0);
    col.rebuildShape(); // call rebuildShape() for my position change to take effect.

↑ Back to top


setActive(value)

Enables/disables the If Collide node.

Parameters

boolean value – true to enable the node, false to disable it

↑ Back to top


setAffectedAsset(value)

Changes the affected asset of the If Collide node.

Parameters

string value – the new affected asset. Possible values: kNone, kCharacter, kEnemy, kPlatform, kCoin

↑ Back to top


setMesh(meshModel)

Sets the mesh of the collision shape using a MeshModel script attribute. See attribute() in the Script section for more information.

Parameters

MeshModel mesh – the new mesh of the collision shape

↑ Back to top


setMesh(value)

Sets the mesh of the collision shape using a string name. It is recommended to use a MeshModel script attribute instead, to avoid issues with meshes with the same name.

Parameters

string mesh – the name of the new mesh

↑ Back to top


setShapePosition(x, y, z)

Sets the position of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

Parameters

number x – the x coordinate position
number y – the y coordinate position
number z – the z coordinate position

↑ Back to top


setShapeRotation

Sets the rotation of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

Parameters

number x – the x coordinate rotation
number y – the y coordinate rotation
number z – the z coordinate rotation

↑ Back to top


setShapeScale

Sets the scale of the collision shape. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.

Parameters

number x – the x coordinate scale
number y – the y coordinate scale
number z – the z coordinate scale

↑ Back to top


setShapeType(type)

Sets the collision shape type. Note that you’ll have to call rebuildShape() after using this method for the change to take effect.
It is recommended to use “kHullShape” over “kMeshShape” as it is less memory intensive.

Parameters

string type – The new collision shape type. Possible values: “kCubeShape”, “kSphereShape”, “kCylinderShape”, “kHullShape”, “kMeshShape”

↑ Back to top


shapePosition()

Returns the position of the collision shape.

Returns

Vec3 the {x, y, z} position coordinates of the collision shape

↑ Back to top


shapeRotation()

Returns the rotation of the collision shape.

Returns

Vec3 the {x, y, z} rotation coordinates of the collision shape

↑ Back to top


shapeScale()

Returns the scale of the collision shape.

Returns

Vec3 the {x, y, z} scale coordinates of the collision shape

↑ Back to top


shapeType()

Returns the type of the collision shape.

Returns

string the collision shape type. Possible values: “kCubeShape”, “kSphereShape”, “kCylinderShape”, “kHullShape”, “kMeshShape”

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Entity – API Reference

By |

Entity

An Entity is an object that exists in your 2D/3D world.

Function Description
addChild(entity) Makes the specified entity a child of the current Entity.
camera() Returns the Camera within the world where the Entity exists. This could be a UI camera or a Scene camera.
children() Returns the array of child Entities that this Entity has.
color() Returns the color of the Entity’s 3D Model in RGBA (Red, Green, Blue, Alpha) format.
component(name) Searches for the component with the specified name in the current Entity and returns it if it’s found. Otherwise, returns null.
components() Returns an array containing all the entity’s components (also known as nodes).
createComponent(type, name) Creates a new component (Node) and activates it. Currently these components can be created programmatically: Animation, 3D Model, and If Collide.
When creating a 3D Model node this way, a mesh must be set before functions like setPosition() can be used on it.
Please see setMesh() for more notes on recommended usage.
forceInit() Forces a newly created Entity to initialize right away.
globalDepth() Returns the depth of the Entity in a 2D World.
id() Returns the Entity’s unique id. Each instance of the Entity in the Scene will have a different id.
isCharacter() Returns if the Entity is a Character (vs an Object).
isRemoved() Returns if the Entity has been removed or not.
isVisible() Returns if the Entity is visible.
level() Returns the LevelSector that the Entity exists in. This refers to the Scene Selector “level” at the bottom of the screen in a 2D/3D World.
linkedEntities() Returns the array of Entities linked to this one with the Linker.
localAABB() Returns the local “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity and for ray casting.
name() Returns the Asset name assigned to Entity.
parent() Returns the Entity’s parent, or null if it doesn’t have one.
physics() Returns the Physics Component of the Entity. null is returned if physics is not enabled for this Entity (the checkbox on the Start node).
position() Returns the Entity’s position relative to its parent. If the Entity has no parent, the result of this function will be no different than worldPosition.
remove() Removes the Entity from the Scene.
removeComponent(component) Removes the given component on the next frame.
rotation() Returns the rotation of the Entity (relative to its parent) in degrees (Vec3).
rotationQuat() Returns the rotation of the Entity (relative to its parent) in Quaternion.
setParent(parent) Sets the Entity as a child of the given parent entity or scene, removing it from its current parent.
scale() Returns the scale of the Entity in Vec3.
setAnimate(value) Enables/disables animation on the Entity. In this case, “animation” is referring to the position, rotation, and scale animations in the editor.
setCastShadows(value) Enables/disables shadow casting of all 3D Models within the Entity at once.
setColor(r, g, b, a) Sets the color of every 3D model within the Entity. Uses RGB (Red, Green, Blue) format. The minimum value is 0 and the maximum is 255. For example, {r:0, g:0, b:0} is black and {r:255, g:255, b:255} is white. Alpha is an optional parameter and sets the opacity of the 3D Model.
setGlobalDepth(value) Set the depth of the Entity in a 2D World.
setOpacity(value) Sets opacity of every 3D model and animation in the Entity.
setPosition(x, y, z) Sets the position of the Entity relative to the Entity’s parent. If the Entity has no parent, this sets the world position of the Entity.
setWorldPosition(x, y, z) Sets the world position of the Entity, not relative to any parent.
setReceiveShadows(value) Enables/disables shadow receiving of all 3D Models within the Entity at once.
setRotation(x, y, z) Sets the rotation value of the Entity, in degrees. This will affect the rotation of every 3D Model within the Entity.
setRotationQuat(value) Sets rotation value in Quaternion.
setScale(x, y, z) Sets the scale of the Entity. This will affect the scale of every 3D Model within the Entity.
setTexture(name) Applies a new texture to all 3D Models within the Entity. The texture should be present in Sprite Editor.
setVisible(value) Sets the visibility of the Entity; true if the Entity is visible, false if not.
transform() Returns the transformation matrix of the Entity.
transformedAABB() Returns the relative “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity relative to its parent, and for ray casting.
transformedOBB() Returns the “oriented bounding box” for the Entity relative to its parent. OBB is more precise but more performance-heavy than AABB.
worldAABB() Returns the world (absolute) “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity and for ray casting.
worldOBB() Returns the “oriented bounding box” for the Entity. OBB is more precise but more performance-heavy than AABB.
worldPosition() Returns the entity’s position coordinates in the world (absolute position).
worldRotation() Returns the entity’s rotation in degrees (not relative to its parent).
worldRotationQuat() Returns the entity’s rotation in Quaternion (not relative to its parent).

addChild(entity)

Makes the specified entity a child of the current Entity.

Entity entity the Entity object that will become the child of the Entity you’re calling the method on.

let ent = this.scene().create('Cone');
this.entity().addChild(ent);

↑ Back to top


camera()

Returns the Camera within the world where the Entity exists. This could be a UI camera or a Scene camera.

Returns

Camera The Camera within the world where the Entity exists.

↑ Back to top


children()

Returns the array of child Entites that this Entity has.

Returns

array The array of children Entities that this Entity has.

let children = this.entity().children();
// reset position of all children
for (i = 0; i <children.length; i++){
  children[i].setPosition(0, 0, 0);
}

↑ Back to top


color()

Returns the color of the Entity’s 3D Model in RGBA (Red, Green, Blue, Alpha) format. The minimum value is 0 and the maximum is 255. For example, {r:0, g:0, b:0, a:1} is black and {r:255, g:255, b:255, a:1} is white.
Note, if the Entity has multiple 3D Model nodes, this function will return the color of the first one that was created.

Returns

Object {r, g, b, a} color pigment of the Entity’s 3D Model.

let ent = this.scene().create("Cube");
log(ent.color().r); // result: the red component of the cube's color.

↑ Back to top


component(name)

Searches for the component with the specified name in the current Entity and returns it if it’s found. Otherwise, returns null. Note that if you have multiple components with the same name, component() will simply return the first one it finds. It’s advised to give your components unique names to avoid bugs.

Parameters

string name – The name of the component to search for.

Returns

Component The Component object found with the given name.

let collide = this.entity().component('If Collide');
if(collide){ // check that collide is not null
  let obj = collide.collisionObject();
}

↑ Back to top


components()

Returns an array containing all the components in the Entity’s mind map.

Returns

Array – array of components

↑ Back to top


createComponent(type, name)

Creates a new component (Node) and activates it. Currently these components can be created programmatically: Animation, 3D Model, and If Collide.
When creating a 3D Model node this way, a mesh must be set before functions like setPosition() can be used on it.
Please see setMesh() for more notes on recommended usage.

Parameters

string type – Possible inputs: “Animation”, “3D Model”, or “If Collide”
string name – The name of the new component.

Returns

Component the newly created component (Animation, 3D Model, or If Collide).

let modelComp = this.entity().createComponent("3D Model", "myModel");
modelComp.setMesh(this.attribute("meshAttribute"));
modelComp.setPosition(0, 10, 0); // now that a mesh is set, any Model 3D functions can be used

let animComp = this.entity().createComponent("Animation", "myAnim");
animComp.setAnimation(this.attribute("bounceAnimation"));

let collideComp = this.entity().createComponent("If Collide", "myCollide");
collideComp.setActive(true);

↑ Back to top


forceInit()

Normally Entities are initialized (which includes running their scripts’ init() functions) on the next frame. Calling this function on a newly created Entity will initialize right away instead. This can be useful if you have variables or functions being created in the Entity’s init() function that will need to be accessed immediately by the Entity creating it. Check out the simple example below.

// first entity
function start(){
    let ent = this.scene().create('Enemy');
    ent.forceInit();
    // without forceInit(), this call would fail because ent isn't initialized yet:
    ent.testFunction("Hello World");
}

// spawned entity
function init(){
    this.entity().testFunction = (string) => log(string); // logs the string passed to it
}

↑ Back to top


globalDepth()

Returns the global depth of the Entity. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Returns

number – The global depth of the Entity

↑ Back to top


id()

Returns the Entity’s unique id. Each instance of the Entity in the Scene will have a different id, including Entities that are made using this.scene().create().

Returns

number – the Entity’s id

↑ Back to top


isCharacter()

Returns if the Entity is a Character (vs an Object).

Returns

boolean true if the Entity is a Character, false if the Entity is not.

↑ Back to top


isRemoved()

Returns if the Entity has been removed or not.

Returns

boolean true if the Entity is has been removed, false if not.

↑ Back to top


isVisible()

Returns if the Entity is visible.

Returns

boolean true if the Entity is visible, false if the Entity is not.

↑ Back to top


level()

Returns the LevelSector that the Entity exists in. This refers to the Scene Selector “level” at the bottom of the screen in a 2D/3D World.

Returns

LevelSector The LevelSector that the Entity exists in.

// remove all cubes from level 5
let cubes = this.scene().find("Cube");
for (int i=0; i<cubes.length; i++){
  if (cubes[i].level().name() == "5"){
    cubes[i].remove();
  }
}

↑ Back to top


linkedEntities()

Returns the array of Entities linked to this one with the Linker.

Returns

Array of Entities linked to this one.

↑ Back to top


localAABB()

Returns the local “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity and for ray casting.

Returns

AABB AABB object containing relative AABB data

↑ Back to top


name()

Returns the Asset name assigned to Entity.

Returns

string name of the Asset assigned to the Entity.

↑ Back to top


parent()

Returns the Entity’s parent, or null if it doesn’t have one.

Returns

Entity the parent Entity of this Entity, or null if no parent exists.

let parent = this.entity().parent();

↑ Back to top


physics()

Returns the Physics Component of the Entity. null is returned if physics is not enabled for this Entity (the checkbox on the Start node).

Returns

Physics Component the Physics Component of the entity

let physics = this.entity().physics();
if(physics){ // check that physics is not null
  physics.setLinearVelocity(0, 20, 0);
}

↑ Back to top


position()

Returns the Entity’s position relative to its parent. If the Entity has no parent, the result of this function will be no different than worldPosition.

Returns

Vec3 {x, y, z} relative coordinates of the Entity.

let pos = this.entity().position();
log('X position = ' + pos.x);

↑ Back to top


remove()

Removes the Entity from the Scene. Note that if you try to access this Entity after it has been removed, you’ll get a null reference error. To protect from this, check this.entity().isRemoved() first.

//Remove an entity if it goes further than 10 units on the X axis.
let pos = this.entity().position()
if(pos.x > 10){
  this.entity().remove();
}

↑ Back to top


removeComponent(component)

Removes the given component on the next frame. The component object is required as a parameter; this can be found by name with this.entity().component(name) for example.

Parameters

Component component The component to remove

↑ Back to top


rotation()

Returns the rotation of the Entity in degrees (Vec3) relative to its parent.

Returns

Vec3 The {x, y, z} rotation value of the Entity, in degrees.

↑ Back to top


rotationQuat()

Returns the rotation of the Entity in Quaternion relative to its parent.

Returns

Quaternion The rotation value in Quaternion.

↑ Back to top


setParent(parent)

Sets the Entity as a child of the given parent entity or scene, removing it from its current parent. If passed null, the Entity will be parented to the current scene.

Parameters

Entity/LevelSector parent The new parent of the Entity

↑ Back to top


scale()

Returns the scale of the Entity in Vec3.

Returns

Vec3 The {x, y, z} scale value of the Entity.

↑ Back to top


setAnimate(value)

Enables/disables animation on the Entity. In this case, “animation” is referring to the position, rotation, and scale animations in the editor.

Parameters

boolean value – True if enabled, false if disabled.

↑ Back to top


setCastShadows(value)

Enables/disables shadow casting of all 3D Models within the Entity at once.

Parameters

boolean value – True if enabled, false if disabled.

↑ Back to top


setColor(r, g, b, a)

Sets the color of every 3D model within the Entity. Uses RGB (Red, Green, Blue) format. The minimum value is 0 and the maximum is 255. For example, {r:0, g:0, b:0} is black and {r:255, g:255, b:255} is white. Alpha is an optional parameter and sets the opacity of the 3D Model.

Parameters

number r – the red component of the color
number g – the green component of the color
number b – the blue component of the color
number a – (Optional) The alpha component of the color. Range: 0-255

↑ Back to top


setGlobalDepth(value)

Sets the global depth of the Entity. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Parameters

number value – The global depth of the Entity

↑ Back to top


setOpacity(value)

Sets opacity of every 3D model and animation in the Entity.

Parameters

number value – Range: 0-1. The lower the value, the less opaque the Entity becomes.

↑ Back to top


setPosition(x, y, z)

Sets the position of the Entity relative to the Entity’s parent. If the Entity has no parent, this sets the world position of the Entity.

Parameters

number x – X coordinate in 3D space
number y – Y coordinate in 3D space
number z – Z coordinate in 3D space

↑ Back to top


setWorldPosition(x, y, z)

Sets the world position of the Entity, not relative to any parent.

Parameters

number x – X coordinate in 3D space
number y – Y coordinate in 3D space
number z – Z coordinate in 3D space

↑ Back to top


setReceiveShadows(value)

Enables/disables shadow receiving of all 3D Models within the Entity at once.

Parameters

boolean value – True if enabled, false if disabled.

↑ Back to top


setRotation(x, y, z)

Sets the rotation value of the Entity, in degrees. This will affect the rotation of every 3D Model within the Entity. Note that if you go past 360 degrees in either direction, the rotation will reset back to under 360 to avoid numbers getting extremely large. For example, if you pass 365 to this function and then checked the rotation with this.entity().rotation();, it would return 5.

Parameters

number x – the X rotation of the Entity
number y – the Y rotation of the Entity
number z – the Z rotation of the Entity

↑ Back to top


setRotationQuat(value)

Sets rotation value in Quaternion.

Parameters

Quaternion value – The Quaternion rotation value to be set

↑ Back to top


setScale(x, y, z)

Sets the scale of the Entity. This will affect the scale of every 3D Model within the Entity.

Parameters

number x – The scale of the Entity on the x axis
number y – The scale of the Entity on the y axis
number z – The scale of the Entity on the z axis

↑ Back to top


setTexture(name)

Applies a new texture to all 3D Models within the Entity. The texture should be present in Sprite Editor.

Parameters

string name – The name of the texture to be applied.

if(health <= 0.5){
  this.entity().setTexture('Damaged Texture');
}

↑ Back to top


setVisible(value)

Sets the visibility of the Entity; true if the Entity is visible, false if not.

Parameters

boolean value – the visibility of the Entity.

↑ Back to top


transform()

Returns the transformation matrix of the Entity.

Returns

Mat4 the Mat4 transformation matrix of the Entity.

↑ Back to top


transformedAABB()

Returns the relative “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity relative to its parent, and for ray casting.

Returns

AABB AABB object containing relative AABB data

↑ Back to top


transformedOBB()

Returns the “oriented bounding box” for the Entity relative to its parent. OBB is more precise but more performance-heavy than AABB.

Returns

OBB OBB object containing relative OBB data

↑ Back to top


worldAABB()

Returns the world (absolute) “axis-aligned bounding box” for the Entity. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far). Useful for checking the size of your Entity and for ray casting.

Returns

AABB AABB object containing world AABB data

↑ Back to top


worldOBB()

Returns the “oriented bounding box” for the Entity. OBB is more precise but more performance-heavy than AABB.

Returns

OBB OBB object containing OBB data

↑ Back to top


worldPosition()

Returns the entity’s position coordinates in the world (absolute position).

Returns

Vec3 the {x, y, z} world coordinates of the Entity

let pos = this.entity().worldPosition();
log('X World Position = ' + pos.x);

↑ Back to top


worldRotation()

Returns the Entity’s rotation in the world (not relative to its parent) in degrees.

Returns

Vec3 the {x, y, z} world rotation of the Entity

let rot = this.entity().worldRotation();
log('World Rotation = ' + rot);

↑ Back to top


worldRotationQuat()

Returns the Entity’s rotation in the world (not relative to its parent) in Quaternion.

Returns

Quaternion the world rotation of the Entity in Quaternion
↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Custom Nodes – API Reference

By |

Custom Nodes

A node is a piece of functionality that exists within a Node Map. If you have an idea for a custom node, you can make one yourself and share it online as a .bbnode file with JSON formatting.

As of release 3.4.1 you can now create a custom node (or group of nodes) and right click > export! This .bbnode or .bbgroup file can then be dragged into any node map to be reused, no code required. Nodes that are exported this way cannot be edited in a text editor.

To create a custom node, you need a basic understanding of JSON formatting and a text editor of your choice. To modify a pre-existing node, see Customizing Nodes.

Writing your own Custom Node

Let’s look at a simple example – the “Set Color” node. Here’s the full .bbnode file:

{
	"name" : "Set Color",
	"attributes": [
		{
			"name" : "Set",
			"type" : "Boolean",
			"connection" : "Input",
			"editable" : false		
		},
		{
			"name" : "Done",
			"type" : "Boolean",
			"connection" : "Output",
			"editable" : false		
		},
		{
			"name" : "Color",
                        "type" : "Color",
			"connection" : "None",
			"editable" : true
		}

	],
	"script":"
        function init(){
        }


        function update(dt){
        }


        function signal(name, value) {
            //Check the incoming signals
            if (name == 'Set' && value) {
                //get the node attributes
                let col = this.attribute('Color');
                
                //set the entity color
                this.entity().setColor(col.r, col.g, col.b, col.a);
                
                //Emit signal to indicate the node finished
                this.emitSignal('Done', true);
            }
        }
    "

}

This results in the following node and attributes:

Now let’s look at it line by line.


name

"name" : "Set Color",

This defines what name this node will have.


attributes

"attributes": []

This array defines what attributes the node will have in the attributes sidebar. It also details any input or output connections the node will have. Please note that the Fields and Possible Values here are all cAsE sEnSiTiVe!

Field Description Possible Values
name Required. The name of the attribute or connection. Any string
*do not give two attributes in the same node the same name!
type Required. What data type the attribute contains. Asset
Animation
Boolean
Color
Dropdown
Mesh
Number
Slider
Text
Vector2D
Vector3D
connection Required. Whether this attribute is an input or output connection. Input
Output
None
editable Required.
Attribute: Whether this attribute is visible & editable in the attribute sidebar.
Connection: Whether the name of this connection can be altered.
true
false
essential Optional (defaults to false). If this field is set to true, then this attribute will be displayed on the Entity’s attribute sidebar when clicked in the asset window. You are marking this attribute as important enough to be accessible from the world view instead of just the entity’s mind map. true
false
hasVariance Optional (for number or vector attributes only). If this field is set to true, then this attribute will display a variance field next to its value. (see Wave node documentation for an example) true
false
self Optional. If you’d like your node to be able to be referenced by other nodes without using signals, set this to true to make the purple connection circle visible. (See requested() for more information) “self”: { “visible” : true }
“self”: { “visible” : false }
value Optional field used to define a default value for the attribute. For instance, your Number type attribute could have a default value of 100 with “value”: 100.
Value is required for a Dropdown type attribute because all possible values are pre-defined.
Dropdown Example from Advanced Move node:

"value": {
    "default": "kReplace",
    "options": {
        "Replace": "kReplace",
        "Add": "kAdd",
        "Multiply": "kMultiply"
    }
}

Example for a Vector3D attribute (leaving the X and Z values blank with null):
“value”: [null, 20, null]

sliderMin
sliderMax
sliderStepSize
sliderDefaultValue
Required fields for a Slider type attribute. sliderMin and sliderMax define the range of the slider, sliderStepSize defines the increment of the slider, and sliderDefaultValue defines the initial value of the slider. Example of a Slider attribute:

{
    "name": "My Slider",
    "type": "Slider",
    "connection": "None",
    "editable": true,
    "sliderMin": 0,
    "sliderMax": 10,
    "sliderStepSize": 2,
    "sliderDefaultValue": 2
}

script

"script":"

Anything you put in this string will be inserted into the Script section of the Node. Since it’s all defined within a string, make sure to use single quotes (‘) instead of double quotes (“) to avoid terminating the string early.

If you save your .bbnode file as a .json file and use a program that has syntax highlighting (such as Visual Studio Code), this section will highlight with errors. This is because normal JSON doesn’t allow multiline strings; this is an area where the .bbnode format differs from JSON.

Here’s another script example, this time from the Jump node. This code snippet is entirely contained within the “script”: ” … ” section of the Jump.bbnode file.

    //Input Signal variables
    let _enabled = true;

    //Node attribute variables
    let _jumpLimit;
    let _jumpForce;

    //working variables
    let _physics;
    let _jumpCount = 0;

    function init(){
        //get the node attributes
        _jumpForce = this.attribute('Jump Force');
        _jumpLimit = this.attribute('Jump Limit');
    
        //Get and check the Physics status of this entity
        _physics = this.entity().physics();
        if(_physics && _physics.type() != 'kDynamic'){
            warning('Jump Node only works with [Dynamic] bodies. Enabling by default');

            _physics.setType('kDynamic');
        }
    }

    function start(){

    }

    function update(dt){

    }

    function signal(name, value){
        //Check the incoming signals
        if(name == 'Jump' && value){
            //check we have dynamic physics on the entity
            if(_physics){
                //check here if the signal to jump again is valid
                //we need to check we are with the jump limit
                if(_jumpLimit == 0 || _jumpCount < _jumpLimit){
                    //calculate the jump force to be applied
                    let vel = _physics.linearVelocity();
                    if(_jumpForce.x != null){
                        vel.x = _jumpForce.x;
                    }
                    if(_jumpForce.y != null){
                        vel.y = _jumpForce.y;
                    }
                    if(_jumpForce.z != null){
                        vel.z = _jumpForce.z;
                    }
                    
                    //apply the jump velocity
                    _physics.setLinearVelocity( vel.x, vel.y, vel.z );

                    //track the jump count
                    _jumpCount++;
                }
            }
        }
        else if(name == 'Reset' && value){
            //Signal to reset the jump so we just reset the 
            //jumpcount variable
            _jumpCount = 0;
        }
    }

Import a Node

To import a node into BuildBox, drag it from your file explorer into the mind map of the Entity you’d like to add it to. Voilà!

Troubleshooting

If you drag your .bbnode into the mind map and nothing happens, that probably means there’s a typo somewhere.

– Make sure that each attribute includes all the required fields.
– Make sure that you have no trailing commas.
– A JSON Validator will give you errors based on the Script section, because as noted above, JSON doesn’t normally allow multiline strings. You can try pasting your .bbnode contents into a JSON Validator and then deleting the script section to look for errors elsewhere.

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Camera – API Reference

By |

Camera

The Camera object can be aquired by calling this.scene().camera(). With it you can manipulate the attributes of your game’s camera.

Function Description
farPlane()

Returns the far render distance of the camera.

fieldOfView()

Returns the field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

followForce()

Returns the follow force of the camera. This determines how much ‘force’ the camera follows an object with.

followOffset()

Returns the follow offset of the camera. The camera will follow the object from this many units away.

followThreshold()

Returns the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving.

nearPlane()

Returns the near render distance of the camera. This is the minimum distance from the camera that an object will be rendered.

orthoScale()

Returns the orthographic scale of the camera (only works if camera projection is orthographic)

position()

Returns the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will return {0, 0, 0} until the relative position is changed with setPosition(), even if you adjust the camera position in the settings.

projection()

Returns the projection type of the camera. There are only two possibilities, kPerspective or kOrthogonal.

rotation()

Returns the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will return {0, 0, 0} until the relative rotation is changed with setRotation(), even if you adjust the rotation of your camera in the settings.

rotationFollowSmooth()

Returns the rotation smoothness of the camera. The range is 0-1. This is like the coefficient of Quaternion.slerp().

screenCenterRay()

Casts a ray based on the center of the Camera. The object returned has the properties origin and direction.

screenRay(point)

Casts a ray based on the given screen point. The object returned has the properties origin and direction. This is useful in coordination with Physic’s World’s rayTest().

screenToWorld(screenPoint)

Converts the given Vec2 screenPoint to a 3D World Position.

setFarPlane(value)

Sets the far render distance of the camera. This is the maximum distance from the camera that an object will be rendered.

setFieldOfView(value)

Sets field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

setFollowForce(x, y, z)

Sets the follow force of the camera. This determines how much ‘force’ the camera follows an object with.

setFollowOffset(x, y, z)

Sets the follow offset of the camera. The camera will follow the object from this many units away.

setFollowThreshold(x, y, z)

Sets the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving.

setNearPlane(value)

Sets the Near Render Distance of the camera. This is the minimum distance from the camera that an object will be rendered.

setOrthoScale(value)

Sets the orthographic scale of the camera (only works if camera projection is orthographic)

setPosition(x, y, z)

Sets the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will not override a camera’s position in the settings, but adjust the position relative to the original camera position.

setPositionFollow(value)

Sets which object the Camera will follow. There are four options you can pass.
1. “None” – Camera will not follow anything
2. “Game Path” – Game Path will be followed
3. “Character” – Any Entity that is considered a Character will be followed
4. The Asset attribute that will be followed

setProjection(value)

Sets the projection type of the camera. There are two possibilities: kPerspective or kOrthogonal.

setProjectionMatrix(matrix)

Sets a custom projection matrix.

setRotation(x, y, z)

Sets the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will not override a camera’s rotation in the settings, but adjust the rotation relative to the original camera rotation.

setRotationFollow(value)

Sets the object whose rotation the Camera will match. There are four options you can pass. “None” – Camera will not match anything for rotation
“Game Path” – Game Path’s rotation will be matched
“Character” – Any Entity that is considered a Character will be followed for rotation
The Asset attribute whose rotation the camera will match

setRotationFollowSmooth(value)

Sets the rotation smoothness of the camera. The range is 0-1. This is like the coefficient of Quaternion.slerp().

setRotationQuat(value)

Sets the “additional” rotation in Quaternion. Note that unlike in Entity, these “setRotation” and “setRotationQuat” are independent, meaning that the result rotation will be a sum of these two.

setWorldPosition(x, y, z)

Sets the actual position of the camera, the same way it is set in the camera settings panel. Note that if the camera is set to follow position of a character or path, this function won’t work. Use setPosition() to change the camera’s position relative to the object it’s following.

worldPosition()

Returns the actual position of the camera. This is the same position as the one set in the camera settings panel.

worldRotation()

Returns the actual rotation of the camera. This is the same rotation as the one set in the camera settings panel.

worldToScreen(x, y, z)

Projects a World (3D) position into Screen (2D) coordinates.


farPlane()

Returns the far render distance of the camera.

Returns

number The Far Render Distance of the camera. This is the maximum distance from the camera that an object will be rendered.

↑ Back to top


fieldOfView()

Returns the field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

Returns

number the field of view of the camera.

↑ Back to top


followForce()

Returns the follow force of the camera. This determines how much ‘force’ the camera follows an object with.

Returns

Vec3 the {x, y, z} follow force of the camera.

↑ Back to top


followOffset()

Returns the follow offset of the camera. The camera will follow the object from this many units away.

Returns

Vec3 the {x, y, z} follow offset of the camera.

↑ Back to top


followThreshold()

Returns the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving.

Returns

Vec3 the {x, y, z} follow threshold of the camera.

↑ Back to top


nearPlane()

Returns the near render distance of the camera. This is the minimum distance from the camera that an object will be rendered.

Returns

number The near render distance of the camera.

↑ Back to top


orthoScale()

Returns the orthographic scale of the camera (only works if camera projection is orthographic)

Returns

number the orthographic scale of the camera

↑ Back to top


position()

Returns the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will return {0, 0, 0} until the relative position is changed with setPosition(), even if you adjust the camera position in the settings.

Returns

Vec3 the {x, y, z} relative position of the camera.

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.position()); // result: {0, 0, 0}
camera.setPosition(0, 10, 0); // the camera still follows the Character, but 10 units higher
log(camera.position()); // result: {0, 10, 0}

↑ Back to top


projection()

Returns the projection type of the camera. There are only two possibilities, kPerspective or kOrthogonal.

Returns

string “kPerspective” if the projection is Perspective, “kOrthogonal” if the projection is Orthogonal

↑ Back to top


rotation()

Returns the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will return {0, 0, 0} until the relative rotation is changed with setRotation(), even if you adjust the rotation of your camera in the settings.

Returns

Vec3 the {x, y, z} relative rotation of the camera.

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.rotation()); // result: {0, 0, 0}, regardless of camera settings
camera.setRotation(30, 0, 0); // the camera still follows the Character, but rotated on the X axis
log(camera.position()); // result: {30, 0, 0}

↑ Back to top


rotationFollowSmooth()

Returns the rotation smoothness of the camera. The range is 0-1. This is like the coefficient of Quaternion.slerp().

Returns

number the rotation follow smoothness/coefficient

↑ Back to top


screenCenterRay()

Returns a ray cast at the center of the Camera. The object returned has the properties origin and direction.

Returns

Object the ray cast into the 3D world based on the screen point

↑ Back to top


screenRay(point)

Returns a ray cast at the given screen point. The object returned has the properties origin and direction. This is useful in coordination with Physic’s World’s rayTest().

Parameters

Vec2 point – an {x, y} coordinate on the screen

Returns

Object the ray cast into the 3D world based on the screen point

function touchBegan(point){
    let cam = this.scene().camera();
    let ra = cam.screenRay(pt);
    log(ra.origin);
    log(ra.direction);
}

↑ Back to top


screenToWorld(screenPoint)

Converts the given Vec2 screenPoint to a 3D World Position.

Parameters

Vec2 screenPoint – an {x, y} coordinate on the screen

Returns

Vec3 the {x, y, z} 3D world coordinate relative to the given Vec2 screenPoint

function touchMove(point){
  // move an entity to the point where the user is touching the screen.
  let pos = this.scene().camera().screenToWorld(point);
  this.entity().setPosition(pos.x, pos.y, pos.z);
}

↑ Back to top


setFarPlane(value)

Sets the far render distance of the camera. This is the maximum distance from the camera that an object will be rendered.

Parameters

number value – the new far render distance of the camera. Minimum 100.

↑ Back to top


setFieldOfView(value)

Sets field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

Parameters

number value – the field of view, from a range of 10-100. The smaller the number, the more “focused in” your field of view becomes.

↑ Back to top


setFollowForce(x, y, z)

Sets the follow force of the camera. This determines how much ‘force’ the camera follows an object with. Another way to think of this is the speed at which your camera reacts to the object’s movement.

Parameters

number x – the x axis component of the follow force
number y – the y axis component of the follow force
number z – the z axis component of the follow force

↑ Back to top


setFollowOffset(x, y, z)

Sets the follow offset of the camera. The camera will follow the object from this many units away.

Parameters

number x – the x axis component of the follow offset
number y – the y axis component of the follow offset
number z – the z axis component of the follow offset

↑ Back to top


setFollowThreshold(x, y, z)

Sets the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving. A 0 follow threshold means the camera will start moving as soon as the object does, whereas a 100 means the camera starts moving when the object is 100 units away. This function also accepts a Vec3 optionally instead of x, y, z.

Parameters

number x – the x axis component of the follow threshold
number y – the y axis component of the follow threshold
number z – the z axis component of the follow threshold

↑ Back to top


setNearPlane(value)

Sets the Near Render Distance of the camera. This is the minimum distance from the camera that an object will be rendered.

Parameters

number value – The Near Render Distance of the camera.

↑ Back to top


setOrthoScale(value)

Sets the orthographic scale of the camera (only works if camera projection is orthographic)

Parameters

number value – the new orthographic scale of the camera

↑ Back to top


setPosition(x, y, z)

Sets the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will not override a camera’s position in the settings, but adjust the position relative to the original camera position.

Parameters

number x – the relative x axis position
number y – the relative y axis position
number z – the relative z axis position

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.position()); // result: {0, 0, 0}
camera.setPosition(0, 10, 0); // the camera still follows the Character, but 10 units higher
log(camera.position()); // result: {0, 10, 0}

↑ Back to top


setPositionFollow(value)

Sets which object the Camera will follow. There are four options you can pass.
1. “None” – Camera will not follow anything
2. “Game Path” – Game Path will be followed
3. “Character” – Any Entity that is considered a Character will be followed
4. The Asset attribute that will be followed

Parameters

string/Asset – “None”, “Game Path”, “Character”, or Asset attribute

↑ Back to top


setProjection(value)

Sets the projection type of the camera. There are two possibilities: kPerspective or kOrthogonal. If an invalid string is passed, will default to perspective.

Parameters

string – two possibilities: “kPerspective” or “kOrthogonal”

↑ Back to top


setProjectionMatrix(matrix)

Sets a custom projection matrix.

Parameters

Mat4 matrix – custom projection matrix

↑ Back to top


setRotation(x, y, z)

Sets the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will not override a camera’s rotation in the settings, but adjust the rotation relative to the original camera rotation.

Parameters

number x – the relative x axis rotation
number y – the relative y axis rotation
number z – the relative z axis rotation

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.rotation()); // result: {0, 0, 0}, regardless of camera settings
camera.setRotation(30, 0, 0); // the camera still follows the Character, but rotated on the X axis
log(camera.position()); // result: {30, 0, 0}

↑ Back to top


setRotationFollow(value)

Sets the object whose rotation the Camera will match. There are four options you can pass.
1. “None” – Camera will not match anything for rotation
2. “Game Path” – Game Path’s rotation will be matched
3. “Character” – Any Entity that is considered a Character will be followed for rotation
4. The Asset attribute whose rotation the camera will match

Parameters

string/Asset – “None”, “Game Path”, “Character”, or Asset attribute

↑ Back to top


setRotationFollowSmooth(value)

Sets the rotation smoothness of the camera. The range is 0-1. This is like the coefficient of Quaternion.slerp().

Parameters

number value – the new rotation follow smoothness/coefficient

↑ Back to top


setRotationQuat(value)

Sets the “additional” rotation in Quaternion. Note that unlike in Entity, these “setRotation” and “setRotationQuat” are independent, meaning that the result rotation will be a sum of these two.

Parameters

Quaternion value – the new rotation in Quaternion

↑ Back to top


setWorldPosition(x, y, z)

Sets the actual position of the camera, the same way it is set in the camera settings panel. Note that if the camera is set to follow position of a character or path, this function won’t work. Use setPosition() to change the camera’s position relative to the object it’s following.
Take care when using setWorldPosition and setPosition together, as setPosition sets a relative position based on the camera’s world position.

Parameters

number x – the x-axis component of the new world position
number y – the y-axis component of the new world position
number z – the z-axis component of the new world position

↑ Back to top


worldPosition()

Returns the actual position of the camera. This is the same position as the one set in the camera settings panel.

Returns

Vec3 {x, y, z} position of the camera

↑ Back to top


worldRotation()

Returns the actual rotation of the camera. This is the same rotation as the one set in the camera settings panel.

Returns

Quaternion the rotation of the camera in Quaternion

↑ Back to top


worldToScreen(x, y, z)

Projects a World (3D) position into Screen (2D) coordinates.

Parameters

number x – the x-axis 3D coordinate
number y – the y-axis 3D coordinate
number z – the z-axis 3D coordinate

Returns

Vec2 the resulting 2D screen coordinates

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

Background Music – API Reference

By |

Background Music

The BackgroundMusic class can be used to control the Background Music of a UI Screen Node.

Static Function Description
play(sound, looped)

Sets the audio track of the Background Music and plays it.

stop()

Stops the Background Music.

setVolume(volume)

Sets the volume of the Background Music, range 0 (muted) to 1 (max).

volume()

Returns the volume of the Background Music, range 0 (muted) to 1 (max).


play(sound, looped)

Sets the audio track of the Background Music and plays it.

Parameters

Sound sound – The new audio to play as Background Music. Sound is a Script node attribute.
boolean looped – Optional. Set the Background Music to loop if true, or stop after one play if false.

function start(){
     let track2 = this.attribute('track2');
     BackgroundMusic.play(track2);
}


A screenshot showing the Sound attribute used in the code example.

↑ Back to top


stop()

Stops the Background Music.

↑ Back to top


setVolume(volume)

Sets the volume of the Background Music, range 0 (muted) to 1 (max).

Parameters

number – the new volume of the Background Music

↑ Back to top


volume()

Returns the volume of the Background Music, range 0 (muted) to 1 (max).

Returns

number – the volume of the Background Music

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?

3D Model – API Reference

By |

3D Model

A 3D Model node is the 3D mesh that provides a shape for your character or object. An entity can contain many 3D Models.

Function Description
castsShadow()

Returns whether this 3D Model casts shadow.

color()

Returns the color of the 3D Model.

globalDepth()

Returns the depth of the 3D Model in a 2D World.

isVisible()

Returns if the 3D Model is visible.

localAABB()

Returns the local “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

mesh()
position()

Returns the 3D Model’s position relative to its Entity.

receivesShadows()

Returns whether this 3D Model receives shadows.

rotation()

Returns the rotation of the 3D model.

scale()

Returns the scale of the 3D model.

setCastShadow(value)

Enables/disables shadow casting of the 3D Model.

setColor(r, g, b, a)

Sets the color of the 3D Model.

setGlobalDepth(value)

Set the depth of the 3D Model in a 2D World.

setMesh(meshModel)

Sets the mesh by using a Mesh Attribute value. A Mesh Attribute can be added to your script node by clicking the script node, then clicking “Add Attribute” in the bottom right of the screen. It is recommended to use this method when setting a mesh programmatically, because it avoids potential issues with multiple meshes with the same name.

setMesh(value)

Sets the mesh by using a string name.

setPosition(x, y, z)

Sets the position {x, y, z} of the 3D Model.

setReceiveShadows(value)

Enables/disables shadow receiving of the 3D Model.

setRotation(x, y, z)

Sets the rotation {x, y, z} of the 3D Model.

setScale(x, y, z)

Sets the scale {x, y, z} of the 3D Model.

setTexture(name)

Sets the texture of the 3D Model. Can be set with the name of the texture or with a texture attribute (see attribute()).

setTextureOffset(x, y)

Sets the offset of the texture assigned to the 3D Model. The texture is repeated if this is used.

setTextureScale(x, y)

Sets the scale of the texture assigned to the 3D Model. If the value is less than 0, the texture will be repeated.

setVisible()

Sets the visibility of the 3D Model.

textureOffset()

Returns the texture offset of the 3D Model.

textureScale()

Returns the texture scale.

transformedAABB()

Returns the relative “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

transformedOBB()

Returns the “oriented bounding box” for the 3D Model relative to its parent. OBB is more precise but more performance-heavy than AABB.

worldAABB()

Returns the world (absolute) “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

worldOBB()

Returns the “oriented bounding box” for the 3d Model. OBB is more precise but more performance-heavy than AABB.


castsShadow()

Returns whether this 3D Model casts shadow.

Returns

boolean – true if the 3D Model casts a shadow, false if not

↑ Back to top


color()

Returns the color of the 3D Model. Each {red, green, blue, alpha} component is range 0-255.

Returns

Object – the {r, g, b, a} representation of the color.

↑ Back to top


globalDepth()

Returns the global depth of the 3D Model. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Returns

number value – The global depth of the 3D Model

↑ Back to top


isVisible()

Returns if the 3D Model is visible.

Returns

boolean true if the 3D Model is visible, false if the 3D Model is not.

↑ Back to top


localAABB()

Returns the local “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

Returns

AABB AABB object containing relative AABB data

↑ Back to top


mesh()

Returns

Mesh Model the mesh object of the 3D Model

↑ Back to top


position()

Returns the 3D Model’s position relative to its Entity.

Returns

Vec3 the {x, y, z} relative coordinates of the 3D Model.

function start(){
  let pos = this.entity().component("3D Model").position();
  log("position x: ", pos.x, " y: ", pos.y, " z:", pos.z);
}

↑ Back to top


recievesShadows()

Returns whether this 3D Model receives shadows.

Returns

boolean – true if the 3D Model receives shadows, false if not

↑ Back to top


rotation()

Returns the rotation of the 3D model.

Returns

Vec3 the {x, y, z} rotation of the 3D Model.

↑ Back to top


scale()

Returns the scale of the 3D model.

Returns

Vec3 the {x, y, z} scale of the 3D Model.

↑ Back to top


setCastShadow(value)

Sets whether this 3D Model casts a shadow.

Parameters

boolean value – true if the 3D Model casts a shadow, false if not

↑ Back to top


setColor(r, g, b, a)

Sets the color of the 3D Model.

Parameters

number r – the red component of the color
number g the green component of the color
number b the blue component of the color
number a (Optional) The alpha component of the color. Range: 0-255

↑ Back to top


setGlobalDepth(value)

Sets the global depth of the 3D Model. Depth decides which object is on top in a 2D World. A higher value will be above a lower number in the Scene.

Parameters

number value – The global depth of the 3D Model

↑ Back to top


setMesh(meshModel)

Sets the mesh by using a Mesh Attribute value. A Mesh Attribute can be added to your script node by clicking the script node, then clicking “Add Attribute” in the bottom right of the screen. It is recommended to use this method when setting a mesh programmatically, because it avoids potential issues with multiple meshes with the same name.

Parameters

MeshModel mesh – The Mesh Attribute that the 3D Model will be set to.

let model = this.entity().component("CharacterBody");
model.setMesh(this.attribute("mySphere")); // mySphere was created in the right sidebar when the script node was open.

↑ Back to top


setMesh(value)

Sets the mesh by using a string name.

Parameters

string value – name of the mesh that the 3D Model will be set to.

↑ Back to top


setReceiveShadows(value)

Sets whether this 3D Model receives shadows.

Parameters

boolean value – true if the 3D Model receives shadows, false if not

↑ Back to top


setPosition(x, y, z)

Sets the position {x, y, z} of the 3D Model.

Parameters

number x – The x-axis component of the position
number y – The y-axis component of the position
number z – The z-axis component of the position

↑ Back to top


setRotation(x, y, z)

Sets the rotation {x, y, z} of the 3D Model.

Parameters

number x – The x-axis component of the rotation
number y – The y-axis component of the rotation
number z – The z-axis component of the rotation

↑ Back to top


setScale(x, y, z)

Sets the scale {x, y, z} of the 3D Model.

Parameters

number x – The x-axis component of the scale
number y – The y-axis component of the scale
number z – The z-axis component of the scale

↑ Back to top


setTexture(name)

Sets the texture of the 3D Model. Can be set with the name of the texture or with a texture attribute (see attribute()).

Parameters

string name – The name of the texture to be applied to the 3D Model. Or
SpriteModel texture – The texture attribute to be applied to the 3D Model.

↑ Back to top


setTextureOffset(x, y)

Sets the offset of the texture assigned to the 3D Model. The texture is repeated if this is used.

Parameters

number x – the x offset of the texture
number y – the y offset of the texture

↑ Back to top


setTextureScale(x, y)

Sets the scale of the texture assigned to the 3D Model. If the value is less than 0, the texture will be repeated.

Parameters

number x – the x scale of the texture
number y – the y scale of the texture

↑ Back to top


setVisible()

Sets the visibility of the 3D Model.

Parameters

boolean value – true for visible, false for not visible.

↑ Back to top


textureOffset()

Returns the texture offset of the 3D Model.

Returns

Vec2 the {x, y} texture offset of the 3D Model

↑ Back to top


textureScale()

Returns the texture scale.

Returns

Vec2 the {x, y} scale of the texture assigned to the 3D Model.

↑ Back to top


transformedAABB()

Returns the relative “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

Returns

AABB AABB object containing relative AABB data

↑ Back to top


transformedOBB()

Returns the “oriented bounding box” for the 3D Model relative to its parent. OBB is more precise but more performance-heavy than AABB.

Returns

OBB OBB object containing relative OBB data

↑ Back to top


worldAABB()

Returns the world (absolute) “axis-aligned bounding box” for the 3D Model. These coordinates form a box with the minimum corner at (left, bottom, near) and the maximum corner at (right, top, far).

Returns

AABB AABB object containing world AABB data

↑ Back to top


worldOBB()

Returns the “oriented bounding box” for the 3d Model. OBB is more precise but more performance-heavy than AABB.

Returns

OBB OBB object containing OBB data

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.

Tell us how we can improve this post?