Physics Component

Cocos Creator currently provides users with a variety of collider components, common rigid body components, as well as tool-type constant force components.

Collider Component

The collider component is used to represent the shape of the collision body of a rigid body. Different geometric shapes have different properties.

Note: the following property names are all lowercase in the actual code. Note: currently only box, sphere and capsule are supported in builtin.

BoxCollider

BoxCollider

PropertiesDescription
materialThe physics material referenced by the collider (the default physics material was referenced when it is empty)
isTriggerWhether it is a trigger, the trigger will not generate physical feedback
centerThe origin of the shape in the local coordinate system
sizeThe size of the box, ie length, width, height

To use BoxCollider, please refer to the BoxCollider API.

SphereCollider

SphereCollider

PropertiesDescription (Other reference box colliders)
radiusRadius of the sphere

To use SphereCollider, please refer to the SphereCollider API.

CylinderCollider

CylinderCollider

PropertiesDescription (Other reference box colliders)
directionThe reference axis of the cylinder’s extended direction
heightThe total height of the cylinder
radiusThe radius of the circular surfaces at both ends of the cylinder

To use CylinderCollider, please refer to the CylinderCollider API.

CapsuleCollider

CapsuleCollider

PropertiesDescription (Other reference cylinders and box colliders)
cylinderHeightThe height of the cylinder in the capsule
radiusThe radius of the sphere in the capsule

To use CapsuleCollider, please refer to the CapsuleCollider API.

Note: cannon.js does not support capsule components. It is recommended to use two spheres and cylinders and piece them together.

ConeCollider

ConeCollider

PropertiesDescription (Other reference cylinders and box colliders)
radiusThe radius of the circle of the underside of the cone
heightThe height of the cone

To use ConeCollider, please refer to the ConeCollider API.

PlaneCollider

PlaneCollider

PropertiesDescription (Other reference box colliders)
normalThe normal vector to the plane
constantThe distance that the plane moves along the normal vector

To use PlaneCollider, please refer to the PlaneCollider API.

MeshCollider

MeshCollider

PropertiesDescription (Other reference box colliders)
meshThe mesh asset referenced by the mesh collider, used to initialize the mesh collision volume
convexWhether used the convex hull of the mesh is approximated, the number of vertices of the mesh should be less than 255 (through which any convex collider and dynamic rigid body can be supported).

To use MeshCollider, please refer to the MeshCollider API.

Note: cannon.js has poor support for the mesh collider component, and only allows detection with the sphere\plane collider. Note: currently only ammo.js backend supports convex functionality.

SimplexCollider

SimplexCollider

PropertiesDescription (Other reference box colliders)
shapeTypeThere are four types of simplex: point, line, triangular face and tetrahedron
vertex0Vertex 0 of the simplex, point (consisting of 0)
vertex1Vertex 1 of the simplex, line (consisting of 0,1)
vertex2Vertex 2 of the simplex, triangular face (consisting of 0,1,2)
vertex3Vertex 3 of the simplex, tetrahedron (consisting of 0,1,2,3)

Note: cannon.js has imperfect support for line and triangular face.

To use SimplexCollider, please refer to the SimplexCollider API.

RigidBody

In order to more easily simulate physical behavior, Cocos Creator provides users with rigid body components.

RigidBody

PropertiesDescription (The property values ​​in the above picture are all default values)
groupThe group of the physics element
massThe mass of the object
typeThe type of the rigid body
linearDampingLinear damping, used to reduce the linear velocity of an object
angularDampingAngular damping, used to reduce the rotation rate of objects
useGravityWhether the rigid body is affected by gravity
linerFactorLinear factor, which can affect the change of linear velocity in each axis
angularFactorRotation factor, which can affect the change of the rotation speed of each axis

To use RigidBody, please refer to the RigidBody API.

ConstantForce

This is a tool component that depends on a RigidBody and will apply a given force and torque to a rigid body every frame.

ConstantForce

PropertiesDescription
forceThe force applied to the rigid body in the world coordinate system
localForceThe force applied to the rigid body in the local coordinate system
torqueTorque applied to the rigid body in the world coordinate system
localTorqueTorque applied to the rigid body in the local coordinate system

To use ConstantForce, please refer to the ConstantForce API.