Functions and messages for collision object physics interaction with other objects (collisions and ray-casting) and control of physical behaviors.
See PhysicsProperties
for related properties.
See PhysicsMessages
for related messages.
Static methods
staticcreate_joint(joint_type:PhysicsJointType, collisionobject_a:HashOrStringOrUrl, joint_id:HashOrString, position_a:Vector3, collisionobject_b:HashOrStringOrUrl, position_b:Vector3, ?properties:PhysicsFixedJoint):Void
staticcreate_joint(joint_type:PhysicsJointType, collisionobject_a:HashOrStringOrUrl, joint_id:HashOrString, position_a:Vector3, collisionobject_b:HashOrStringOrUrl, position_b:Vector3, ?properties:PhysicsHingeJoint):Void
staticcreate_joint(joint_type:PhysicsJointType, collisionobject_a:HashOrStringOrUrl, joint_id:HashOrString, position_a:Vector3, collisionobject_b:HashOrStringOrUrl, position_b:Vector3, ?properties:PhysicsSliderJoint):Void
staticcreate_joint(joint_type:PhysicsJointType, collisionobject_a:HashOrStringOrUrl, joint_id:HashOrString, position_a:Vector3, collisionobject_b:HashOrStringOrUrl, position_b:Vector3, ?properties:PhysicsSpringJoint):Void
Create a physics joint between two collision object components.
Note: Currently only supported in 2D physics.
Parameters:
joint_type | the joint type |
---|---|
collisionobject_a | first collision object |
joint_id | id of the joint |
position_a | local position where to attach the joint on the first collision object |
collisionobject_b | second collision object |
position_b | local position where to attach the joint on the second collision object |
properties | optional joint specific properties table See each joint type for possible properties field. |
staticdestroy_joint(collisionobject:HashOrStringOrUrl, joint_id:HashOrString):Void
Destroy an already physics joint. The joint has to be created before a destroy can be issued.
Note: Currently only supported in 2D physics.
Parameters:
collisionobject | collision object where the joint exist |
---|---|
joint_id | id of the joint |
staticget_gravity():Vector3
Get the gravity in runtime. The gravity returned is not global, it will return the gravity for the collection that the function is called from.
Note: For 2D physics the z component will always be zero.
staticget_joint_properties(collisionobject:HashOrStringOrUrl, joint_id:HashOrString):EitherType<PhysicsFixedJoint, EitherType<PhysicsHingeJoint, EitherType<PhysicsSliderJoint, PhysicsSpringJoint>>>
Get a table for properties for a connected joint. The joint has to be created before properties can be retrieved.
Note: Currently only supported in 2D physics.
Parameters:
collisionobject | collision object where the joint exist |
---|---|
joint_id | id of the joint |
Returns:
properties table. See the joint types for what fields are available
staticget_joint_reaction_force(collisionobject:HashOrStringOrUrl, joint_id:HashOrString):Vector3
Get the reaction force for a joint. The joint has to be created before the reaction force can be calculated.
Note: Currently only supported in 2D physics.
Parameters:
collisionobject | collision object where the joint exist |
---|---|
joint_id | id of the joint |
Returns:
reaction force for the joint
staticget_joint_reaction_torque(collisionobject:HashOrStringOrUrl, joint_id:HashOrString):Float
Get the reaction torque for a joint. The joint has to be created before the reaction torque can be calculated.
Note: Currently only supported in 2D physics.
Parameters:
collisionobject | collision object where the joint exist |
---|---|
joint_id | id of the joint |
Returns:
the reaction torque on bodyB in N*m.
staticraycast(from:Vector3, to:Vector3, groups:Table<Int, Hash>):PhysicsMessageRayCastResponse
Requests a ray cast to be performed.
Ray casts are used to test for intersections against collision objects in the physics world.
Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
do not intersect with ray casts.
Which collision objects to hit is filtered by their collision groups and can be configured
through groups
.
The actual ray cast will be performed during the physics-update.
Parameters:
from | the world position of the start of the ray |
---|---|
to | the world position of the end of the ray |
groups | a lua table containing the hashed groups for which to test collisions against |
staticraycast_async(from:Vector3, to:Vector3, groups:Table<Int, Hash>, ?request_id:Int):Void
Requests a ray cast to be performed.
Ray casts are used to test for intersections against collision objects in the physics world.
Collision objects of types kinematic, dynamic and static are tested against. Trigger objects
do not intersect with ray casts.
Which collision objects to hit is filtered by their collision groups and can be configured through groups
.
The actual ray cast will be performed during the physics-update.
- If an object is hit, the result will be reported via a
ray_cast_response
message. - If there is no object hit, the result will be reported via a
ray_cast_missed
message.
Parameters:
from | the world position of the start of the ray |
---|---|
to | the world position of the end of the ray |
groups | a lua table containing the hashed groups for which to test collisions against |
request_id | a number between [0,-255]. It will be sent back in the response for identification, 0 by default |
staticset_gravity(gravity:Vector3):Void
physics.set_gravity(gravity)
Set the gravity in runtime. The gravity change is not global, it will only affect the collection that the function is called from.
Note: For 2D physics the z component of the gravity vector will be ignored.
Parameters:
gravity | the new gravity vector |
---|
staticset_hflip(url:HashOrStringOrUrl, flip:Bool):Void
Flips the collision shapes horizontally for a collision object
Parameters:
url | the collision object that should flip its shapes |
---|---|
flip |
|
staticset_joint_properties(collisionobject:HashOrStringOrUrl, joint_id:HashOrString, properties:PhysicsFixedJoint):Void
staticset_joint_properties(collisionobject:HashOrStringOrUrl, joint_id:HashOrString, properties:PhysicsHingeJoint):Void
staticset_joint_properties(collisionobject:HashOrStringOrUrl, joint_id:HashOrString, properties:PhysicsSliderJoint):Void
staticset_joint_properties(collisionobject:HashOrStringOrUrl, joint_id:HashOrString, properties:PhysicsSpringJoint):Void
Updates the properties for an already connected joint. The joint has to be created before properties can be changed.
Note: Currently only supported in 2D physics.
Parameters:
collisionobject | collision object where the joint exist |
---|---|
joint_id | id of the joint |
properties | joint specific properties table Note: The collide_connected field cannot be updated/changed after a connection has been made. |
staticset_vflip(url:HashOrStringOrUrl, flip:Bool):Void
Flips the collision shapes vertically for a collision object
Parameters:
url | the collision object that should flip its shapes |
---|---|
flip |
|