Physics

Make things bounce, collide, react to hits and manage constraints.

getPhysicsType(entity)

Get the physics type for this body.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
int

setPhysicsType(entity, physicsType)

Set the physics type for this body.

Arguments
entity: Entity, a pointer to an entity in the world.
physicsType: int, available values are PHYSICS_NONE, PHYSICS_STATIC, PHYSICS_KINEMATIC, PHYSICS_DYNAMIC, PHYSICS_NO_INHERIT,

hasInheritedPhysics(entity)

Return true if this entity is inheriting physics from a parent.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
bool

getPhysicsGravity(entity)

Get the gravity factor for this physics entity. The value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsGravity(entity, gravityFactor)

Set the gravity factor for this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
gravityFactor:

setPhysicsShapeType(entity, physicsShape)

Set the physics shape type for this entity.

Arguments
entity: Entity, a pointer to an entity in the world.
physicsShape: int, available values are PHYSICS_SHAPE_BOX, PHYSICS_SHAPE_CAPSULE, PHYSICS_SHAPE_COMPOUND,

getPhysicsShapeType(entity)

Get the physics shape type for this entity.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
int

updatePhysicsShape(entity)

update the physics shape from the model, useful if you have generated or modified a model at runtime

Arguments
entity: Entity, a pointer to an entity in the world.

isPhysicsTrigger(entity)

Check if this entity is a physics trigger.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
bool

setPhysicsTrigger(entity, callback)

Set this entity as trigger, a callback will be fired each time a physics entity enters the trigger's physics shape. Setting the callback to nil will switch off the trigger.

Arguments
entity: Entity, a pointer to an entity in the world.
callback:

setPhysicsVelocity(entity, velocity)

Set the linear velocity, this is a trajectory vector that will influence the motion of this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
velocity: vec3

getPhysicsVelocity(entity)

Get the linear velocity, this is the trajectory vector that is currently determining the motion of this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
vec3

setPhysicsAngularVelocity(entity, velocity)

Set the angular velocity, this is a trajectory vector that will influence the rotation of this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
velocity: vec3

getPhysicsAngularVelocity(entity)

Get the angular velocity, this is the trajectory vector that is currently determining the rotation of this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
vec3

findPhysicsCastHit(entity, castTransform)

Check if a physics entity will collide at a given pose in space (castTransform), useful to check for a collision before it happens and react to it.

Arguments
entity: Entity, a pointer to an entity in the world.
castTransform: Transform

Return
hit , hit.entities (list of intersecting entities), hit.normal (vec3 to move away from collision), hit.depth (multiply this by hit.normal to fully get out of the collision).

getPhysicsRestitution(entity)

Get how much restitution force (bounce) you get when a physics entity collides. Value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsRestitution(entity, restitution)

Set how much restitution force (bounce) you get when a physics entity collides.

Arguments
entity: Entity, a pointer to an entity in the world.
restitution: float, a number ranging from 0.0 to 1.0.

getPhysicsFriction(entity)

Get the amount of friction this physics entity will encounter when colliding or sliding. Value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsFriction(entity, friction)

Set the amount of friction this physics entity will encounter when colliding or sliding.

Arguments
entity: Entity, a pointer to an entity in the world.
friction: float, a number ranging from 0.0 to 1.0.

Return
float

getPhysicsDensity(entity)

Get the amount of density for this physics entity. Value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsDensity(entity, density)

Set the amount of density for this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
density: float, a number ranging from 0.0 to 1.0.

getPhysicsLinearDamping(entity)

Get the linear damping for this physics entity. Value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsLinearDamping(entity, damping)

Set the linear damping for this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
damping: float, a number ranging from 0.0 to 1.0.

getPhysicsAngularDamping(entity)

Get the angular damping for this physics entity. Value will range from 0.0 to 1.0.

Arguments
entity: Entity, a pointer to an entity in the world.

Return
float

setPhysicsAngularDamping(entity, damping)

Set the angular damping for this physics entity.

Arguments
entity: Entity, a pointer to an entity in the world.
damping: float, a number ranging from 0.0 to 1.0.

setPhysicsMotionTarget(entity, position, orientation, deltaTime)

Move a physics entity towards a target position and orientation integrating this motion over a certain amount of time.

Arguments
entity: Entity, a pointer to an entity in the world.
position: vec3
orientation: quat
deltaTime: float

makePhysicsConstraint()

Make a constraint entity.

Return
Entity , a pointer to an entity in the world, nil if the entity was not found.

setPhysicsConstrained(constraint, index, entity)

Constrain a physics entity to follow the given constraint.

Arguments
constraint: Entity
index: number, index of the constrained slot, can be 1 or 2.
entity: Entity, a pointer to an entity in the world.

getPhysicsConstrained(constraint, index)

Get the constrained physics entity at a given index.

Arguments
constraint: Entity
index: number, index of the constrained slot, can be 1 or 2.

Return
Entity , a pointer to a physics entity or nil if nothing is constrained at the given index.

setPhysicsConstrainedOffset(constraint, index, offset)

Set the offset from the constraint to the constrained entity.

Arguments
constraint: Entity
index: number, index of the constrained slot, can be 1 or 2.
offset: vec3

getPhysicsConstrainedOffset(constraint, index)

Get the offset from the constraint to the constrained entity.

Arguments
constraint: Entity
index: number, index of the constrained slot, can be 1 or 2.

Return
vec3

getPhysicsConstrainedTransform(constraint, index)

Get the transform for the constrained entity.

Arguments
constraint: Entity
index: number, index of the constrained slot, can be 1 or 2.

Return
Transform

getPhysicsConstraintType(constraint)

Get the type of constraint.

Arguments
constraint: Entity

Return
string

setPhysicsConstraintType(constraint, constraintType)

Set the type of this constraint.

Arguments
constraint: Entity
constraintType: int, available values are PHYSICS_CONSTRAINT_FIXED, PHYSICS_CONSTRAINT_DISTANCE, PHYSICS_CONSTRAINT_HINGE, PHYSICS_CONSTRAINT_POINT, PHYSICS_CONSTRAINT_CONE, PHYSICS_CONSTRAINT_SLIDER,

getPhysicsConstraintConfig(constraint)

Get the configuration of this constraint. The config table will be different depending on the constraint type.

Arguments
constraint: Entity

Return
config , config.enabled, distanceConfig.min/maxDistance, distanceConfig.frequency, distanceConfig.damping, hingeConfig.limisMin/Max, hingeConfig.maxFrictionTorque, coneConfig.halfAngle, sliderConfig.limitsMin/Max, sliderConfig.maxFrictionForce, sliderConfig.frequency, sliderConfig.damping

setPhysicsConstraintConfig(constraint, config)

Set the configuration of this constraint. The config table will need to be different depending on the constraint type.

Arguments
constraint: Entity
config: table, config.enabled, distanceConfig.min/maxDistance, distanceConfig.frequency, distanceConfig.damping, hingeConfig.limisMin/Max, hingeConfig.maxFrictionTorque, coneConfig.halfAngle, sliderConfig.limitsMin/Max, sliderConfig.maxFrictionForce, sliderConfig.frequency, sliderConfig.damping