Physics Introduction
Cocos Creator 3D currently supports the lightweight collision detection system builtin
and the physics engine cannon.js
with physical simulation, and the asm.js
/wasm
version ammo.js
of the powerful physics engine bullet
, also we provides users with efficient component-based workflow and convenient methods of use.
Physics World And Elements
Elements in the physics world can be divided into rigid body. We can adding physics elements by adding a collider (Collider
) or rigid body (RigidBody
) component to the game object. The physics system will perform calculations on these elements to make their behaviors the same with the real world.
Note: The rigid body here doesn't refer to the
RigidBody
component. TheRigidBody
component is used to control the properties related to the physical behavior of the rigid body.
Adding a Physical Element
Adding a physical element to the world can be divided int the following steps:
- Create a new shape
Cube
; - Click
Add Component
on theInspector
panel witch is on the right of editor; - Select
BoxColliderComponent
under thePhysics
menu, and adjust the parameters; - add a
RigidBodyComponent
component in order to make it have physical behavior。
In this way we get a physical element that has both a collider and a physical behavior.
Perfecting The Physics World
We can add a ground to the world. Following the steps 1,2,and 3, you can add another Plane
with collider only.
Then, adjust the view of the camera (select the camera and press the shortcut Ctrl + Shift + F
to align the camera view to screen).
Finally, click the run button, you can see the changes of physical elements in the scene. The final scene is shown in the following figure:
Note: You can see the new preview result on the browser you just ran by clicking the refresh button directly after adjusting the property value of the component.
Composition Of Physical Elements
A physical element can be composed of the following ways:
- A
RigidBody
component - One or more
Collider
components - One
RigidBody
component plus one or more collider components
More Detailed Modules
Additional physics system will be introduced in more detail through the following modules:
Module | Description |
---|---|
Physics Options | Introduces the optional options of low-level physics engine in Cocos Creator 3D |
Physics System | Introduces the physics system and a series of properties and interfaces of the physics system. |
Physics Component | Introduces some physics components and a series of properties on the panel. |
Physics Usage | Further introduces the use of physics, events, group masks, etc. |
Continue to the Physics Options documentation。