Collision between characters

i add ghost control for player

        GhostControl gc = new GhostControl(sphereShape);
        gc.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
        playerVisual.spatial.addControl(gc);
        physics.getPhysicsSpace().add(gc);

and add ghost control for monster

        GhostControl gc = new GhostControl(sphereShape);
        gc.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
        model.addControl(gc);
        physics.getPhysicsSpace().add(gc);

but they don’t collide

How do you know they dont collide properly for a GhostControl?

2 Likes

i dont konow
it is possible that a collision occurs and it can be fixed
but I need them not to pass through each other

then why write “but they don’t collide” ?

did you read the Wiki about them?

1 Like

I read the forum and there they advised to make ghost control for a collision of two characters

why not read the Wiki then?

It will provide you information what is GhostControl really.

read
but my code does not differ from the example

then you didnt read with understanding.

Your answer is in Wiki, in like less than 1 minute of reading. in 6-10 first lines of text.

i will even copy paste Wiki here:

Attach a com.jme3.bullet.control.GhostControl to any Spatial to turn it into a PhysicsGhostObject. Ghost objects automatically follow their spatial and detect collisions. The attached ghost itself is invisible and non-solid (!) and doesn’t interfere with your game otherwise, it only passively reports collisions.

edit: and even bolded text that is your answer.

1 Like

it means ghost control is not solid and you need to look for another way so that the characters do not go through?

then lets again follow wiki:

You can leave the GhostControl non-solid and invisible and attach it to an (invisible) Node in the scene to create something like a motion detector. But a GhostControl also works fine when added to spatials that are solid (with RigidBodyControl) and visible (with Geometry). One use case for GhostControls is to check for collisions among CharacterControls when the characters are walking.

first sentence of bolded.

GhostControl is to test, if the shape intersects with others, for a solid objects use RigidBodyControl, CharacterControl, BetterCharacterControl or VehicleControl.

1 Like

i user cracter control with ghost control

SphereCollisionShape sphereShape = new SphereCollisionShape(1.2f);
        playerVisual.characterControl = new CharacterControl( sphereShape , 1.2f );
        playerVisual.spatial.addControl(playerVisual.characterControl);
        
        playerVisual.characterControl.setPhysicsLocation(new Vector3f(0,0.1f,0));
        
        rootNode.attachChild(playerVisual.spatial);
        
        GhostControl gc = new GhostControl(sphereShape);
        gc.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
        playerVisual.spatial.addControl(gc);
        physics.getPhysicsSpace().add(gc);
        
        rootNode.attachChild(playerVisual.spatial);

how to make them hard?

how to make CharacterControl solid?

code from Wiki with CharacterControl:

one of 6 lines seems answer of mistake you have in code.


// Load any model
Node myCharacter = (Node) assetManager.loadModel("Models/myCharacterModel.mesh.xml");
rootNode.attachChild(myCharacter);
// Create a appropriate physical shape for it
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
CharacterControl myCharacter_phys = new CharacterControl(capsuleShape, 0.01f);
// Attach physical properties to model and PhysicsSpace
myCharacter.addControl(myCharacter_phys);
bulletAppState.getPhysicsSpace().add(myCharacter_phys);
1 Like

remade

SphereCollisionShape sphereShape = new SphereCollisionShape(1.2f);
        playerVisual.characterControl = new CharacterControl( sphereShape , 1.2f );
        playerVisual.spatial.addControl(playerVisual.characterControl);
        
        playerVisual.characterControl.setPhysicsLocation(new Vector3f(0,0.1f,0));
        physics.getPhysicsSpace().add(playerVisual.characterControl);

        rootNode.attachChild(playerVisual.spatial);
        
        GhostControl gc = new GhostControl(sphereShape);
        gc.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
        playerVisual.spatial.addControl(gc);
        physics.getPhysicsSpace().add(gc);
   SphereCollisionShape sphereShape = new SphereCollisionShape(2.0f);
        CharacterControl myThing_phys = new CharacterControl( sphereShape , 1.2f );
        model.addControl(myThing_phys);
        
        monster.control = myThing_phys;
        
        physics.getPhysicsSpace().add(myThing_phys);

        GhostControl gc = new GhostControl(sphereShape);
        gc.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
        model.addControl(gc);
        physics.getPhysicsSpace().add(gc);

but they are still not solid.

ok, i see missing line, tho it should be solid now if its proper physics space.
I dont see all project, so mistake might be anywhere.

My next suggestion for you is to compare JME Walking Character TEST with your code.

working vs not working.

here is test (you can also run Test via SDK Test project to see how it works):

1 Like

it uses character control and rigged body control

and i need to make collision between character control

Why would you want to add charcterControl to a none playable Monster?

so was it a lie again? If it collide with other RigidBodies, then it is solid.

Carpenter asked a good question.