# Collider Collider
The collider component is used to describe the shape of an object in the physical world.
The collider component can be used in conjunction with a rigid body to describe the shape of the rigid body. It can also be used alone. At this time, it is regarded as the collision body attached to a completely stationary rigid body.
# Different collider types
- Basic collision body
- Cuboid collision body
- Sphere collision body
- Capsule collision body-composed of a cylinder plus spheres at both ends
- 3D mesh collision body-3D mesh model can be specified manually
# Important attributes and events
Property name | Description |
---|---|
isTrigger | Whether it is Trigger. **See Trigger for details. * |
material | Physical material. |
Event name | Event object |
---|---|
onCollisionEnter | Collision |
onCollisionStay | Collision |
onCollisionExit | Collision |
onTriggerEnter | TriggerCollision |
onTriggerStay | TriggerCollision |
onTriggerExit | TriggerCollision |
There are two ways to add physical events:
- (Recommended) Use
collider.onCollisionEnter
in the script to get theDelegate
of the event from the collision body, and then use the following methods to add event callbacks:collider.onCollisionEnter.add(collision => { // handle collision });
- In the user script, directly implement the
onCollisionEnter
function, and mount the user script on the node where the collision body is located.export default class MyScript extends engine.Script { public onCollisionEnter(collision: engine.Collision) { // handle collision } }
# Trigger
If the isTrigger
property is true
, the collider will be marked as a Trigger.
The Trigger collision body will not collide with other collision bodies in the physics simulation phase, will not change the motion state of the two due to the collision, and will not generate the onCollisionXX
series of events.
In the physics simulation phase, if a Trigger collider and another Triggers intersect, an event of the onTriggerXX
series will not be generated.
# Use multiple collision bodies to simulate the shape of objects
Sometimes using a single collider cannot meet the needs, and the three-dimensional mesh collider is too performance-consuming. You can consider creating multiple different colliders on the same object to approximate the shape of the simulation.
# Physical Material
Additional Physical Material*resources can be used to describe the physical properties of the collision body surface.
# ▌Physical material properties
Property name | Description |
---|---|
bounciness | The elasticity of the surface of the object, 0 <= bounciness <= 1. |
dynamicFriction | The dynamic friction coefficient of the surface of the object, 0 <= dynamicFriction <= 1. |
staticFriction | The static friction coefficient of the surface of the object, 0 <= staticFriction <= 1. |
# The relationship between different types of collision bodies
# ▌Which collision bodies can collide
Static Collision Body | Rigid Collision Body | Kinematic Rigid Body Collision Body | |
---|---|---|---|
Static collision body | × | ✓ | × |
Rigid body collision body | ✓ | ✓ | ✓ |
Kinematic rigid body Collision body | × | ✓ | × |
# ▌Which colliders can trigger Trigger events
Static Collision Body | Rigid Collision Body | Kinematic Rigid Body Collision Body | |
---|---|---|---|
Static collision body | × | ✓ | ✓ |
Rigid body collision body | ✓ | ✓ | ✓ |
Kinematic Rigid Body Collision Body | ✓ | ✓ | ✓ |