PhysicalTrigger Class
Inherits: | Physical |
Physical triggers fire callbacks when a physical object gets inside or outside of them. To be detected by the trigger, physical objects are required to have at the same time both:
- Bodies (with matching Physical Mask)
For BodyDummy to trigger PhysicalTrigger, you need to call updateContacts() first.
- Shapes (with matching Collision mask)
To force update of the physical trigger updateContacts() can be called. After that, you can access all updated data about the contacts in the same frame. However, callback functions will still be executed only when the next engine function is called: that is, before flush() (in the current frame), or before theupdate() (in the next frame) — whatever comes first.
If you have moved some nodes and want to get callbacks based on changed positions in the same frame, you need to call engine.world.updateSpatial() first.
Usage Example
PhysicalTrigger Class
Members
static PhysicalTrigger(int type, vec3 size)
Constructor. Creates a physical trigger of the specified shape and size.Arguments
- int type - Shape of the physical trigger:
- 0 = Sphere
- 1 = Capsule
- 2 = Cylinder
- 3 = Box
- vec3 size - Size of the physical trigger:
- Radius, in case of a sphere
- Radius and height, in case of a capsule or a cylinder
- Dimensions, in case of the box
PhysicalTrigger cast(Node node)
Casts a PhysicalTrigger out of the Node instance.Arguments
- Node node - Node instance.
Return value
PhysicalTrigger instance.PhysicalTrigger cast(Physical base)
Casts a PhysicalTrigger out of the Physical instance.Arguments
- Physical base - Physical instance.
Return value
PhysicalTrigger instance.Body getBody(int num)
Returns the specified body with which a physical trigger intersects.Arguments
- int num - Body number.
Return value
Intersected body.void setCollisionMask(int mask)
Sets the collision bit mask for the trigger:- the trigger will be activated if the entered body will have a matching Physical Mask and at the same time its shape will have a matching Collision Mask.
Arguments
- int mask - Integer, each bit of which is a mask.
int getCollisionMask()
Returns the collision bit mask for the trigger:- the trigger will be activated if the entered body will have a matching Physical Mask and at the same time its shape will have a matching Collision Mask.
Return value
Integer, each bit of which is a mask.float getContactDepth(int contact)
Returns penetration depth by the given contact.Arguments
- int contact - Contact number.
Return value
Penetration depth.vec3 getContactNormal(int contact)
Returns a normal of the contact point, in world coordinates.Arguments
- int contact - Contact number.
Return value
Normal of the contact point.Object getContactObject(int contact)
Returns an object participating in the contact with a physical trigger.Arguments
- int contact - Contact number.
Return value
Object in contact.Vec3 getContactPoint(int contact)
Returns world coordinates of the contact point.Arguments
- int contact - Contact number.
Return value
Contact point.Shape getContactShape(int contact)
Returns a shape that collided with a physical trigger.Arguments
- int contact - Contact number.
Return value
Shape in contact.int getContactSurface(int contact)
Returns the surface of the current object, which is in contact.Arguments
- int contact - Contact number.
Return value
Surface number.void setEnterCallbackName(string name)
Sets a callback function to be fired on entering the physical trigger.- Unlike setEnterCallback(), this callback function accepts a body that entered the physical trigger and physical trigger itself as arguments.
Arguments
- string name - Name of the UnigineScript callback function.
string getEnterCallbackName()
Returns the name of the UnigineScript callback function fired on entering the physical trigger. This callback function is set via setEnterCallbackName() .Return value
Name of the UnigineScript callback function.void setExclusionMask(int mask)
Sets an bit mask to prevent detecting collisions with shapes and bodies. This mask is independent of the collision mask. To avoid detecting collisions by a physical trigger for bodies and shapes with matching collision masks, at least one bit in exclusion masks should match. 0 is to collide with all bodies and shapes with a matching collision mask.Arguments
- int mask - Integer, each bit of which is a mask.
int getExclusionMask()
Returns the bit mask that prevent detecting collisions with shapes and bodies. This mask is independent of the collision mask. To avoid detecting collisions by a physical trigger for bodies and shapes with matching collision masks, at least one bit in exclusion masks should match.Return value
Integer, each bit of which is a mask.void setLeaveCallbackName(string name)
Sets the name of a UnigineScript callback function to be fired on leaving the physical trigger.- Unlike setLeaveCallback() , this callback function accepts a body that left the physical trigger and physical trigger itself as arguments.
Arguments
- string name - Name of the UnigineScript callback function.
string getLeaveCallbackName()
Returns the name of the UnigineScript callback function fired on leaving the physical trigger. This callback function is set via setLeaveCallbackName() .Return value
Name of the UnigineScript callback function.int getNumBodies()
Returns the total number of bodies intersecting with the physical trigger.Return value
Number of bodies.int getNumContacts()
Returns the total number of contacts with bodies, shapes and colliding surfaces in which a physical trigger participated.Return value
Number of contacts.void setShapeType(int type)
Sets the shape type of the physical trigger.Arguments
- int type - Shape type of the physical trigger:
- 0 - Sphere
- 1 - Capsule
- 2 - Cylinder
- 3 - Box
int getShapeType()
Returns the shape type of the physical trigger.Return value
Shape type of the physical trigger:- 0 - Sphere
- 1 - Capsule
- 2 - Cylinder
- 3 - Box
void setSize(vec3 size)
Sets the size of the physical trigger.Arguments
- vec3 size - New size of the physical trigger:
- Radius, in case of a sphere (pass the radius in the first element of the vector).
- Radius and height, in case of a capsule or a cylinder (pass the radius as the first vector element and the height as the second element).
- Dimensions along the X, Y and Z axes, in case of the box.
vec3 getSize()
Returns the current size of the physical trigger:- Radius, in case of a sphere (pass the radius in the first element of the vector).
- Radius and height, in case of a capsule or a cylinder (pass the radius as the first vector element and the height as the second element).
- Dimensions along the X, Y and Z axes, in case of the box.
Return value
Size of the physical trigger.int type()
Returns the type of the node.Return value
Physical trigger type identifier.void updateContacts()
Forces a physical trigger to be updated, i.e. to recalculate its intersections with physical objects and colliders. After that, you can access all updated data; however, callback functions themselves will be executed only when physics flush is over.Last update: 2017-12-21
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)