How can i work with gravity in cocos creator?

How can i remove physicsboxcollider and physicscirclecollider? Or at least make it transparent? and how to detect boxcollider and circlecollider collision separately? i mean if i hit the box collider it will say box.Please help me. TIA.

prblm

The colliders don’t render on the screen, you might’ve enabled some debugs which displays the colliders.
There is no way to distinguish callbacks from different shapes of colliders, PhysicsCollider and Collider sets off different events. To distinguish between a box collider and a circle collider callback I’d suggest you to use different nodes for each collider as child nodes instead of attaching different collider components on a single node. If you wish to put multiple colliders on a single node, you can use the “tag” property in the collider to separate them, and you can set these tags in the inspector (editor).

2 Likes

You don’t need to remove PhysicsCollider, you must have turned on physics debug somewhere in your code.

        cc.director.getPhysicsManager().debugDrawFlags = cc.PhysicsManager.DrawBits.e_shapeBit;

Remove this & you won’t see Collideres getting rendered in your game.

To differentiate the colliders on same node use tag on colliders. e.g. Give tag 1 to BoxCollider & Give tag 2 to the CircleCollider in the editor & check for tags in script while detecting collision.

4 Likes

Thank you very much.

can you please give an example code or line how to differentiate the colliders on same node use tag on colliders??

Attach this to object with multiple colliders

    onCollisionEnter(other, self) {
        if(self.tag == 1) {
            // Box collider hit 
        }
        else if(self.tag == 2) {
            // Circle collider hit
        }
    }
4 Likes