刚体组件
刚体的种类有几种:
- static
0质量、0速度,不受重力影响。适用建筑物、地面等 - dynamic
有质量,服从牛顿定律。 - kinematic
0质量、可以有速度。比如子弹这种小质量物体
需要在脚本中
cc.director.getphysicsManager().enabled=true
物理碰撞组件:
- Friction 摩擦系数,比如在一个斜坡下滑时
- Restitution弹性系数,规定相撞时的反弹能力
注意:
- 物理组件的碰撞不需要再开启碰撞系统,物理系统的开启已含有他。
- 该碰撞同样受项目分组的影响,要在项目面板中设定好组,防止碰撞被忽略或者响应。
碰撞回调
- 开启碰撞监听
选中节点的RigidBody组件,Enable Contact Listener - 附加脚本
onBeginContact(contact,self,other)
onEndContact(contact,self,other)
onPreSolve(contact,self,other)
onPostSolve(contact,self,other)
其中,各个参数的类型为:
contact:cc.PhysicsContact表示本次接触事件
selfCollider:cc.PhysicsCollider表示本节点的碰撞体