Physic 2d - how to handle collision?

Hi,
I’m a newbie. I’m using cocos creator 3x. I’m making character and weapon. I have player node and weapon is a child node. Now I need handle collision of weapon with other collider(enemy…). I know sine cocos creator 3x we need add rigidbody2d to handle collision. And I add rigidbody2d with body type kinematic for player node and weapon node. But when I move player node then weapon node don’t move. I think when move parent node then child node will auto move but it wrong for my case. I know we can move weapon collider to player node to don’t use rigidbody for weapon node. But in my case weapon will change position when change other weapon type. what should I do?
P/S: sorry for my English skill

Hello, maybe you can refer to this document.

https://docs.cocos.com/creator/manual/en/editor/components/spine.html#spine-attachment

  1. How are you moving the player? By using force (using physics) or by updating its position property? Refer to each type Here. Some type ignore the mass and may not work with physics.

  2. For your case, you better use “Dynamic” type and turn off allow sleep checkbox as well for both the Player and the Weapon. By using this, walls to stop the player from going thru them as well.

Here’s my settings for Player:

For Weapon (it’s the child node of the Player’s node):

Here’s the video demo for you (click on screen will make the player (Square) move together with the weapon (circle). but it will not go thru wall):

Another trick for working with Collider is enabling debug mode, so that we can see what is going on:

        PhysicsSystem2D.instance.enable = true;

        PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
            EPhysics2DDrawFlags.Pair |
            EPhysics2DDrawFlags.CenterOfMass |
            EPhysics2DDrawFlags.Joint |
            EPhysics2DDrawFlags.Shape;

        let collider = this.getComponent(Collider2D);
        if (collider) {
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
            collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
        }
1 Like

Thanks @StudioAMK . My player use gravity(not set 0) and body type is dynamic. I move player by linearVelocity.

1 Like