如图 用物体A去碰撞物体B,在B检测onCollisionEnter。A的路径是任意的。发生碰撞就停下,怎么知道A物体撞了B物体那条边?
参考了论坛里的写法 var isIn = cc.Intersection.rectRect(selfPreAabb, otherPreAabb) 这样检测左右两边发生碰撞根本进不去 isIn = false ,从B的上下边碰撞可以检测到 isIn = true.
直接用AABB 则可以,通过xMax 或 yMax的比较也判断不了A撞到B的那条边啊。求个思路。。。

想到的代码
onCollisionEnter: function (other, self) {
console.log(‘on collision enter’,self.tag);
var otherAabb = other.world.aabb.clone();
var otherPreAabb = other.world.preAabb.clone();
var selfAabb = self.world.aabb.clone();
var selfPreAabb = self.world.preAabb.clone();
selfPreAabb.y = selfAabb.y;
otherPreAabb.y = otherAabb.y;
if (self.tag == 2 && other.tag == 1 ) {
if (cc.Intersection.rectRect(selfPreAabb, otherPreAabb)){
if (selfAabb.xMax>= otherAabb.xMax) {
console.log("=====>>>>>> 左边进来")
}else{
console.log("=====>>>>>> 右边进来")
}
}
}
},
