Cocos Creator how to use physical engine

1: 3 steps and a hole to turn on the physics engine:

(1) Turn on the engine: cc.director.getPhysicsManager().enabled = true

(2) Configure gravity: cc.director.getPhysicsManager().gravity = this.gravity

p>

(3) Use the switch to control whether to turn on the debugging mode:

share picture

The script code for opening the physics engine must be written in the onLoad function, otherwise it cannot be opened, remember, remember;

p>

2: Edit physical nodes and physical shapes

(1) Create a node , As a carrier;

(2) add a rigid body component instance, configure the type of rigid body, static, dynamic;

(3) to Add a physical shape to the object, which is Collider, also called collider;

It supports rectangular collider, circle, polygon, and can be made into any shape. A node can have multiple shapes.

share picture p>

share picture

3: collision detection

strong>Collision detection is a commonly used function in the physics engine, but it is actually very simple. To get the collision detection car for that node, just hang a script instance on the node, and then reload the physical collision detection function.

onBeginContact/ onEndContact/ onPreSolve/ onPostSolve
4: Collision relationship configuration
Each node will have a group, you can add a group, and then specify the type for the node.

Share picture

Click to edit:

Share a picture

There will be a collision relationship pairing here, and the configuration is correct If you have a collision relationship, you can use it happily. If you still can’t, you can join the group 7051 82 843 to get the completed video tutorial.

Leave a Comment

Your email address will not be published.