[SOLVED] Collision between rigid body control and character control

i have character
character have:
character control
riggid body control

 public GameUnit(String name,String model,String id,LevelAppState appState,Vector3f postion){
        this.name = name;
        this.appState = appState;
        this.model = model;
        this.id = id;
        
        spatial = this.appState.assetManager.loadModel("Models/"+this.model+".glb");
        spatial.setName(id);
        
        this.appState.npcNode.attachChild(spatial);
                
        SphereCollisionShape sphereShape = new SphereCollisionShape(2.0f);
        character = new CharacterControl( sphereShape , 1.2f );
        spatial.addControl(character);
        
        ghost = new GhostControl(CollisionShapeFactory.createDynamicMeshShape(spatial)); 
        spatial.addControl(ghost); 
        
        this.appState.bulletAppState.getPhysicsSpace().add(ghost);
        this.appState.bulletAppState.getPhysicsSpace().add(character);

        character.setPhysicsLocation(postion);
        
        
        Node monsterNode = (Node)spatial;
        Node armature = (Node)monsterNode.getChild("Armature");
       
        animComposer = armature.getControl(AnimComposer.class);        
        animComposer.setCurrentAction("stand");
        
        spatial.addControl(new UnitControl(this));

        CollisionShape shape = CollisionShapeFactory.createMeshShape(spatial);
        RigidBodyControl rig = new RigidBodyControl(shape, 0);
        spatial.addControl(rig);
        
        rig.setKinematicSpatial(true);

        this.appState.bulletAppState.getPhysicsSpace().add(rig);

    }

but when characters collide they run across each other
how to make them stop on collision
like landscape
?

CharacterControl is based on PhysicsCharacter, which ignores collisions with other instances of PhysicsCharacter.

If you want collisions between characters, I suggest switching from CharacterControl to BetterCharacterControl. BetterCharacterControl is based on a rigid body, which (ironically) makes it more flexible and easier to customize.

2 Likes

thanks solved

  public GameUnit(String name,String model,String id,LevelAppState appState,Vector3f postion){
        this.name = name;
        this.appState = appState;
        this.model = model;
        this.id = id;
        
        spatial = this.appState.assetManager.loadModel("Models/"+this.model+".glb");
        spatial.setName(id);
        
        this.appState.npcNode.attachChild(spatial);
                
       // SphereCollisionShape sphereShape = new SphereCollisionShape(2.0f);
        character = new BetterCharacterControl(0.6f, 2f, 1f);
        spatial.addControl(character);
        
        ghost = new GhostControl(CollisionShapeFactory.createDynamicMeshShape(spatial)); 
        spatial.addControl(ghost); 
        
        this.appState.bulletAppState.getPhysicsSpace().add(ghost);
        this.appState.bulletAppState.getPhysicsSpace().add(character);

        character.warp(postion);
        
        
        Node monsterNode = (Node)spatial;
        Node armature = (Node)monsterNode.getChild("Armature");
       
        animComposer = armature.getControl(AnimComposer.class);        
        animComposer.setCurrentAction("stand");
        
        spatial.addControl(new UnitControl(this));
        
    }
1 Like