Physics Component

This component is used for processing physics. You can access the physics component from the Start node.

Function Description
activateBody()

When the body type is “kDynamic” and “Always Active” is disabled, the body will get inactive after a short period of time. This function activates it back.

angularFactor()

Returns the “rotation factor” of the physics component. The angular factor determines how the physics engine affects specific angular/rotation axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

angularVelocity()

Returns the current angular velocity value of the object.

collisionGroup()

Returns the collision group of the object.

disableDeactivation()
gravity()

Returns the gravity value affecting the entity. If it hasn’t been adjusted for this entity, this method will return the gravity value of the Scene.

isPhysics()

Checks if physics is enabled on this entity.

linearFactor()

Returns “position factor” of the physics component. The linear factor etermines how the physics engine affects specific linear/position axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

linearVelocity()

Returns the current linear velocity value of the entity.

mass()

Returns the mass value of the entity. This defaults to 1.

mesh()

Returns the collision shape mesh if assigned. Null if a mesh is not being used as the collision shape.

parentEntity()

Returns the entity that this physics component belongs to.

predictedPosition(time)
rebuildShape()

Call this function to update the physics collision shape. This should be done if you change the shape or scale of your Entity in code.

restitution()

Returns the “Bounce” value of the physics component. The higher the value, the higher the bounce upon collision.

setAngularFactor(x, y, z)

Sets the “rotation factor” of the object. This determines how the physics engine affects specific angular/rotation axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

setAngularVelocity(x, y, z)

Sets the angular velocity value of the object.

setCollisionGroup(group)

Set the collision group of the entity.

setCreated(value)

Enables/disables everything that is connected to the “Start” node.

setDynamic()

Set the physics type to Dynamic.

setGravity(x, y, z)

Sets gravity value affecting this entity. This will override the gravity value in the scene, and will not affect other objects.

setLinearFactor(x, y, z)

Sets the “position factor” of the object. This determines how the physics engine affects specific linear/position axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

setLinearVelocity(x, y, z)

Sets the linear velocity of the entity.

setMass(value)

Sets the mass of the entity. A mass of 0 will not be affected by gravity.

setMesh(mesh)

Sets the mesh of the collision shape from a MeshModel script attribute.

setMesh(name)

Sets the mesh of the collision shape based on the name of the mesh.

setPhysics(value)

Enables/disables physics.

setRestitution(value)

Sets the “Bounce” value of the physics component. The higher the value, the higher the bounce upon collision.

setShapePosition(x, y, z)

Sets the collision shape position of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

setShapeRotation()

Sets the collision shape rotation of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

setShapeScale()

Sets the collision shape scale of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

setShapeType(type)

Sets the shape type. Highly recommended to use “kHullShape” over “kMeshShape”.

setType(value)

Sets the type of the physics body.
kStatic – body is static and will never be moved but other objects can collide with it. Used for ground or walls in your game.
kDynamic – body is fully dynamic and can bounce off of other object and be affected by gravity.
kKinematic – body can be moved by directly setting position and rotation and will not react to other bodies collision or gravity. Used as obstacles or elevator platforms. kDisabled

shapePosition()
shapeRotation()
shapeScale()
shapeType()

Returns the shape type of the collision shape.

type()

Returns the type of the physics body. kStatic – body is static and will never be moved but other objects can collide with it. Used for ground or walls in your game.
kDynamic – body is fully dynamic and can bounce off of other object and be affected by gravity.
kKinematic – body can be moved by directly setting position and rotation and will not react to other bodies collision or gravity. Used as obstacles or elevator platforms. kDisabled


activateBody()

When the body type is “kDynamic” and “Always Active” is disabled, the body will get inactive after a short period of time. This function activates it back.

↑ Back to top


angularFactor()

Returns the “rotation factor” of the physics component. The angular factor determines how the physics engine affects specific angular/rotation axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

Returns

Vec3 the {x, y, z} components of the angular factor.

↑ Back to top


angularVelocity()

Returns the current angular velocity value of the object.

Returns

Vec3 the {x, y, z} components of the angular velocity.

↑ Back to top


collisionGroup()

Returns the collision group of the object.

Returns

string possible values: kNone, kCharacter, kEnemy, kPlatform, kCoin

↑ Back to top


disableDeactivation()

↑ Back to top


gravity()

Returns the gravity value affecting the entity. If it hasn’t been adjusted for this entity, this method will return the gravity value of the Scene.

Returns

number the current gravity value of the entity.

↑ Back to top


isPhysics()

Checks if physics is enabled on this entity.

Returns

boolean true if physics is enabled, false if not.

↑ Back to top


linearFactor()

Returns “position factor” of the physics component. The linear factor etermines how the physics engine affects specific linear/position axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

Returns

Vec3 the {x, y, z} linear factor.

↑ Back to top


linearVelocity()

Returns the current linear velocity value of the entity.

Returns

Vec3 the {x, y, z} linear velocity of the entity.

↑ Back to top


mass()

Returns the mass value of the entity. This defaults to 1.

Returns

number the mass of the entity

↑ Back to top


mesh()

Returns the collision shape mesh if assigned. Null if a mesh is not being used as the collision shape.

Returns

MeshModel the object of the collision shape mesh

↑ Back to top


parentEntity()

Returns the entity that this physics component belongs to.

Returns

Entity the parent entity of the physics component

↑ Back to top


predictedPosition(time)

Parameters

number time – the number of seconds from now that you’d like to predict the position of the entity

Returns

Vec3 entity’s predicted {x, y, z} position after time based on its current Velocity.

↑ Back to top


rebuildShape()

Call this function to update the physics collision shape. This should be done if you change the shape or scale of your Entity in code.

↑ Back to top


restitution()

Returns the “Bounce” value of the physics component. The higher the value, the higher the bounce upon collision.

Returns

number the “Bounce” value of the physics component

↑ Back to top


setAngularFactor(x, y, z)

Sets the “rotation factor” of the object. This determines how the physics engine affects specific angular/rotation axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

Parameters

number x – the x component of the new angular factor
number y – the y component of the new angular factor
number z – the z component of the new angular factor

↑ Back to top


setAngularVelocity(x, y, z)

Sets the angular velocity value of the object.

Parameters

number x – the x component of the new angular velocity
number y – the y component of the new angular velocity
number z – the z component of the new angular velocity

↑ Back to top


setCollisionGroup(group)

Set the collision group of the entity.

Parameters

string group – possible values: kNone, kCharacter, kEnemy, kPlatform, kCoin

↑ Back to top


setCreated(value)

Enables/disables everything that is connected to the “Start” node.

Parameters

boolean value – true to enable, false to disable

↑ Back to top


setDynamic()

Set the physics type to Dynamic.

↑ Back to top


setGravity(x, y, z)

Sets gravity value affecting this entity. This will override the gravity value in the scene, and will not affect other objects.

Parameters

number x – the x component of the new gravity
number y – the y component of the new gravity
number z – the z component of the new gravity

↑ Back to top


setLinearFactor(x, y, z)

Sets the “position factor” of the object. This determines how the physics engine affects specific linear/position axes. For instance of x=0, the physics engine will not calculate physics for that axis. If x=2.0, it will calculate physics magnified by 2.

Parameters

number x – the x component of the new linear factor
number y – the y component of the new linear factor
number z – the z component of the new linear factor

↑ Back to top


setLinearVelocity(x, y, z)

Sets the linear velocity of the entity.

Parameters

number x – the x component of the new linear velocity
number y – the y component of the new linear velocity
number z – the z component of the new linear velocity

↑ Back to top


setMass(value)

Sets the mass of the entity. A mass of 0 will not be affected by gravity.

Parameters

number value – the new mass of the entity

↑ Back to top


setMesh(mesh)

Sets the mesh of the collision shape from a MeshModel script attribute.

Parameters

MeshModel mesh – the new mesh for the collision shape

↑ Back to top


setMesh(name)

Sets the mesh of the collision shape based on the name of the mesh.

Parameters

string name – the new mesh for the collision shape

↑ Back to top


setPhysics(value)

Enables/disables physics.

Parameters

boolean value – true to enable physics, false to disable

↑ Back to top


setRestitution(value)

Sets the “Bounce” value of the physics component. The higher the value, the higher the bounce upon collision.

Parameters

number value – the new “Bounce” value

↑ Back to top


setShapePosition(x, y, z)

Sets the collision shape position of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

Parameters

number x – the x component of the new shape position
number y – the y component of the new shape position
number z – the z component of the new shape position

↑ Back to top


setShapeRotation()

Sets the collision shape rotation of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

Parameters

number x – the x component of the new shape rotation
number y – the y component of the new shape rotation
number z – the z component of the new shape rotation

↑ Back to top


setShapeScale()

Sets the collision shape scale of the object. Note: you must call rebuildShape() after calling this for the change to be reflected in game.

Parameters

number x – the x component of the new shape scale
number y – the y component of the new shape scale
number z – the z component of the new shape scale

↑ Back to top


setShapeType(type)

Sets the shape type. Highly recommended to use “kHullShape” over “kMeshShape”.

Parameters

string type – Possible values: “kCubeShape”, “kSphereShape”, “kCylinderShape”, “kHullShape”, “kMeshShape”.

↑ Back to top


setType(value)

Sets the type of the physics body.
kStatic – body is static and will never be moved but other objects can collide with it. Used for ground or walls in your game.
kDynamic – body is fully dynamic and can bounce off of other object and be affected by gravity.
kKinematic – body can be moved by directly setting position and rotation and will not react to other bodies collision or gravity. Used as obstacles or elevator platforms. kDisabled

Parameters

string type – Possible values: kStatic, kDynamic, kKinematic, kDisabled

↑ Back to top


shapePosition()

Returns

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

↑ Back to top


shapeRotation()

Returns

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

↑ Back to top


shapeScale()

Returns

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

↑ Back to top


shapeType()

Returns the shape type of the collision shape.

Returns

string Possible values: “kCubeShape”, “kSphereShape”, “kCylinderShape”, “kHullShape”, “kMeshShape”.

↑ Back to top


type()

Returns the type of the physics body. kStatic – body is static and will never be moved but other objects can collide with it. Used for ground or walls in your game.
kDynamic – body is fully dynamic and can bounce off of other object and be affected by gravity.
kKinematic – body can be moved by directly setting position and rotation and will not react to other bodies collision or gravity. Used as obstacles or elevator platforms. kDisabled

Returns

string Possible values: kStatic, kDynamic, kKinematic, kDisabled

let ph = this.entity().physics();
if(ph && ph.type() == 'kDynamic'){
  //Dynamic mode
}else{
  //Static or Kinematic mode
}

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.