Cocos Creator Learning (eight) Summary of rigid body, collision components and physical components

Source: Internet
Author: User

1, how to move the rigid body.

2. What is the difference between a collision component and a physical collision component?

3, three kinds of physical collision components are different.

4. How the physical collision component can respond to a collision callback.

5. How does the collision component have a collision callback?


1. How to move a rigid body?

When we have a rigid body on one of our nodes, we want to move. Usually we move through the setposition of the node,

But a rigid body will not be affected, whether it be static, dynamic, or kinematic.

We can pass

1, instantaneous action cc.place to move without affecting the original motion trajectory of the rigid body

2. All actions of action. Cc.moveby;cc.moveto, wait.


2. What is the difference between a collision component and a physical component?

There is no type of collision component, as long as the intersection will occur collision events, if not to deal with the collision, there is no effect.

Physical collision components are divided into types because they bind rigid bodies first. If the rigid body type is different, it will have different effects.

Physicsboxcollider that are bound to dynamtic type rigid bodies are affected by gravity and can be set to speed

A physical component that is bound to a static type rigid body, is not affected by gravity, cannot be set to speed, and can be moved by setting the position

Physical components bound to kinematic type rigid bodies, not affected by gravity, can set the speed



3, three kinds of physical components are different.

A physical component that is bound to a dynamic (motion) type cannot penetrate a physical component that is bound to a static (static) type

A physical component that is bound to a dynamic type cannot penetrate a physical component that is bound to a kinematic type

Static and kinematic do not trigger collision events, and static and static;kinematic and kinematic do not trigger collision events;


4. How the physical component makes a collision callback.

First, rigidbody to turn on collision monitoring.

The following functions are then available under the current node

Called once when the function collision body is first contacted

Onbegincontatct:function (Contact,selfcollider,othercollider) {}

Called once at the end of the two collision body contact

Onendcontact:fucntion (Contact,setcollider,othercollider) {}

Each time the collision body contact logic is to be processed is called

Onpresolve:function (Contact,selfcollider,othercollider) {}

Called each time the collision body contact is processed

Onpostsolve:fucntion (Contact,selfcollider,othercollider) {}


5. Callback of Collision component

var manager = Cc.director.getCollisionManager ();
Manager.enabled = true;
The script first turns on collision monitoring, because the default is to turn off

Then there are the following functions:

Called when a collision is generated

Oncollisionenter:function (other,self) {


}

After a collision has been generated, it is called after each collision result has been calculated before the collision is finished.

Oncollisionstay:function (other,self) {}

Called when the collision is over

Oncollisionexit;function (other,self) {}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.