start() {
let collder = this.getComponent(Collider2D)
if(collder){
collder.on(Contact2DType.BEGIN_CONTACT,this.onBeginContact,this)
collder.on(Contact2DType.END_CONTACT,this.onEndContact,this)
}
}
onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null){
//开始接触调用
console.log('onBeginContact')
//contact获取的是刚体的本地坐标,可通过getWorldManifold转为世界坐标
const worldManifold = contact.getWorldManifold()
//碰撞点数组
const points = worldManifold.points
//碰撞点上的法向量
const normal = worldManifold.normal
}
onEndContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null){
//结束接触调用
console.log('onEndContact')
}