cocos creator 添加多少physics box collider不起作用

看到你有使用 flip action
一个建议是可以将 sprite 放到这个物理节点的子节点,然后对这个 sprite 进行flip action,这样就不会影响到物理节点了

多谢,
你说的

在物理回调里面 rigidbody 会被锁住
你可以记录下这个 rigidbody ,然后在 update 中设置这个值?

这个方法,会有性能开销吗?

会有一点点开销
另一个方式是使用 scheduleOnce 在延迟调用的回调里面设置

动态关闭物,我现在按这个方案做,遇到下面的问题:
Assertion failed! Pls debug.
box2d.js:5518 Uncaught TypeError: Cannot read property ‘aabb’ of undefined
at b2DynamicTree.GetFatAABB (box2d.js:5518)
at b2BroadPhase.TestOverlap (box2d.js:2717)
at b2ContactManager.Collide (box2d.js:11010)
at b2World.Step (box2d.js:9064)
at CCClass.update (CCPhysicsManager.js:181)
at TheClass.update (CCScheduler.js:401)
at TheClass.mainLoop (CCDirector.js:1395)
at callback (CCGame.js:567)
另一个错误是:

可以发个 demo 上来么,我看下你的代码?

sorry, 现在没时间简化个demo出来,
我现在这样移除:
node.removeComponent(cc.PhysicsBoxCollider);
node.removeComponent(cc.RigidBody);
貌似也可以。

这样也可以。。。这些组件被移除的时候是延迟处理的,不过损耗会比设置 rigidbody 的 active 要高

我搞了个简单的demo,
在onBeginContact里面设置 rigidbody.active属性,
在v1.6.0编辑器上跑会有asset错误。麻烦看看

TestPhysics.zip (198.0 K

修改后的 test.js

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
    },

    // use this for initialization
    onLoad: function () {
        this.rigidbody = this.node.getComponent(cc.RigidBody);

        this.disableRigidBody = function () {
            this.rigidbody.active = false;
        }.bind(this);
    },

    onBeginContact: function () {
        this.scheduleOnce(this.disableRigidBody);
    },

    
});

多谢,用scheduleOnce解决问题了
再多问个问题,
碰撞发生时,我们现在想知道是哪个方向发生碰撞了,
我使用:
var worldManifold = contact.getWorldManifold();
var normal = worldManifold.normal;
normal的值调试发现是 (0, 1) (0, -1) (1, 0) (-1, 0)这四个值,我打算用这个作为判断方向,
是否可行?
我们碰撞用的都是PhysicsBoxCollider。

可以的

谢,
我在一个节点上用了PhysicsBoxCollider和PhysicsPolygonCollider,
PhysicsPolygonCollider用来做视野判断,对于PhysicsPolygonCollider,我们只希望得到碰撞通知,不希望会有刚体碰撞效果,
我现在在
onBeginContact 中使用contact.disabledOnce = true,但是没有效果
有其他方案吗?

或者物理组件(Physics)和碰撞组件(Collision)可在一个节点中共存吗?

用这个

多谢,再请教个问题,
我们需要做射线测试,用于视野判断,
cc.PhysicsManager.rayCast貌似不能排除些group,也不能指定只检测某些group。
我们打算用cc.RayCastType.AllClosest来返回所有结果,
想问问,返回的是按远近距离排序后的数组吗?

我记得是乱序的,可以根据 PhysicsRayCastResult.fraction 排个序

好的 多谢,我试试看

再请教个问题
我自己加了寻路组件,
现在可以规划出多个路径点,
我的怪物是用了physics,rigidbody
有啥API可方便地设定rigidbody移动到目的点后停止之类的吗?
我知道有cc.moveBy,但是因为我们用了rigidbody,应该用不了。

你试下用 Kinematic 的 type,然后按正常移动 node 那样移动怪物

onBeginContact(contact, self, other) {
    self.getComponent(cc.RigidBody).node.rotation=90;
}

我再刚体碰撞后想旋转一下刚体,我这样实现没有效果,而且有一个debug信息,信息如下:Assertion failed! Pls debug.
请问如何解决?