Character control to ignore DynamicAnimControl's rigid bodies

Hi,
I have 2 characters in my game each has a character control and dynamic anim control with a few linked joints.
I would like the character control of player1 to ignore the other player’s joints so it will pass through it unlike the behavior demonstrated in the below pic.
So , I have tried to add each player’s character control to the other player joint’s rigid bodies ignore list (see code below) but it doesn’t help.

    public void ignoreJoints(String targetVar, RunTimeVarDef ignoreVarDef) {

        Node model;
        AppModel am = models.get(targetVar);
        if (am == null) {
            return;
        }

        model = am.model;
        if (model == null) {
            return;
        }

        if (am.physicalControl instanceof CharacterControl) {
            CharacterControl ctl = (CharacterControl) am.physicalControl;
            DynamicAnimControl dctl = this.getDynamicAnimControl(ignoreVarDef);
            if(dctl!=null) {
                PhysicsRigidBody[] rigidBodies = dctl.listRigidBodies();
                for(int i=0;i<rigidBodies.length;++i) {
                    ctl.getCharacter().addToIgnoreList(rigidBodies[i]);
                }
            }

        }

    }

Is it even possible? and if so, what should I do different?
Thanks a lot

1 Like

If you’re using Minie, the most straightforward solution is to use the addToIgnoreList() method.

However, addToIgnoreList() works on collision objects, not controls. To access the collision object of a CharacterControl, use the getCharacter() method. To access the collision objects of a DynamicAnimControl, use the listRigidBodies() method.

Alternatively, there are also ways to ignore collisions using collision groups.

2 Likes

I have not tried the “addToIgnoreList” method. I also use the Minie physics engine in my game. I have both BCC (BetterCharacterControl) and DAC (DynamicAnimControl) enabled for my character. In order to avoid them from colliding, I have them Set up a different CollisionGroup and so far this works great.

2 Likes

Thank you @sgold . Maybe I’m missing something but isn’t it exactly what I did in my code?
I got the CharacterControl using getCharacter() and then fetched all collision objects by calling listRigidBodies() and then added to each of the collision objects to the Character control’s ignore list.

I can try switching to another method but I would like to know if adding to ignore list should get the same results if done correctly.
I can try creating a test app for this case if it helps.

Thanks @FoxCC . I need to read about BetterCharacterControl see maybe it’s better using it in my game. I will try switching to using different collision group if we find that the described method I’m currently using is not supposed to work even if done correctly.

OK, I tried switching to using different collision groups for the CharcaterControl’s collision object and the Joints rigid bodies but still - no effect. So, I’m writing a test app to demonstrate the problem

1 Like

I created a test app simulating the situation.
I tried to have each character control ignore the other’s player joint’s rigid bodies but still the character control’s collision shape is stopped when colliding with the joints.
Hope it helps to understand the problem…
I didn’t try yet to use BetterCharacterControl instead of CharacterControl.

Thanks for helping.

1 Like


I ran your test case and I didn’t test why “addToIgnoreList” didn’t work.
I made a simple modification and set up different CollisionGroup for them. The effect is like this. I don’t know if this is what you want.

    this.player1 = loadPlayer(new Vector3f(0,-6,0), 2);  // Load player with collisionGroup = 2
    this.player2 = loadPlayer(new Vector3f(0,1,0), 3);   // Load player with collisionGroup = 3
    // ignoreJoints(this.player1, this.player2);
    // ignoreJoints(this.player2, this.player1);

    ......

    charCtl.getCharacter().setCollisionGroup(1 << collisionGroup);
    for (int i = 0; i < rbs.length; ++i) {
        rbs[i].setCollisionGroup(1 << collisionGroup);
    }

You can also set it up more complexly,
Then BCC objects will collide with each other.

    int normalGroup = 1;
    int bccGroup = 2;
    int dacGroup = 3;
    charCtl.getCharacter().setCollisionGroup(1 << bccGroup);
    charCtl.getCharacter().setCollideWithGroups(normalGroup | (1 << bccGroup));
    for (int i = 0; i < rbs.length; ++i) {
        rbs[i].setCollisionGroup(1 << dacGroup);
    }

Hope this helps.

1 Like

I just found out that it’s better to use these constants from PhysicsCollisionObject.

    int normalGroup = PhysicsCollisionObject.COLLISION_GROUP_01;
    int bccGroup = PhysicsCollisionObject.COLLISION_GROUP_02;
    int dacGroup = PhysicsCollisionObject.COLLISION_GROUP_03;
    charCtl.getCharacter().setCollisionGroup(bccGroup);
    charCtl.getCharacter().setCollideWithGroups(normalGroup | bccGroup);
    for (int i = 0; i < rbs.length; ++i) {
        rbs[i].setCollisionGroup(dacGroup);
    }
1 Like

This could indicate a bug in Bullet. I’ll take a look.

1 Like

Thanks a lot Stephen. meanwhile , I’m checking if using the different collision groups is working for my use cases

1 Like

Thanks a lot! this works as expected. I just need to make sure that it doesn’t interfere with any other collision feature I’m using…

1 Like

I created a test app simulating the situation.

Thanks for the test app.

Apparently, ignore lists have no effect whatsoever on physics characters. This is (even more) obvious in simple tests like HelloWalkOtoCc which have only 2 collision objects in the space. I consider this a bug in Bullet.

I’m developing a fix. For now you should use collision groups instead of ignore lists and/or use BetterCharacterControl instead of CharacterControl.

2 Likes

Thanks a lot Stephen! I will do both - use collision groups and port to BetterCharacterControl

1 Like