Hi,
This post may seems to speak about the same problem as the previous post ( Physics interaction between CharacterControl and RigidBodyControl? )
but, since my problem is far less complex, I took the liberty of creating a new post
With the last update of JME3, I had to discard my PhysicsCharacterNode and replace it by CharacterControls.
With the PhysicsCharacterNode, the characters were colliding with each other.
With the new CharacterControls, they don’t collide.
I don’t really need to know which part of CharacterControl is colliding, I just need the two characters to stop their movements when they collide.
For now my code is as follow :
[java]
private void loadPhysicsNode( Vector3f position, Vector3f direction )
{
//
//Calculate collision shape
//
BoundingBox box = ((BoundingBox)model.getWorldBound());
float xHalfExtent = box.getXExtent();
float yHalfExtent = box.getYExtent();
float zHalfExtent = box.getZExtent();
float radius = Math.max(xHalfExtent, zHalfExtent);
float height = yHalfExtent;
System.out.println( "Height : " + height );
CapsuleCollisionShape shape = new CapsuleCollisionShape( radius, height, 1);
//
//Create physics node
//
this.physicNode = new ForceCharacterControl(shape, 0.01f );
//this.physicNode = new CharacterControl(shape, 0.01f );
this.model.addControl( physicNode );
this.physicNode.setUpAxis(1);
this.physicNode.setGravity(10.0f);
this.physicNode.setFallSpeed(0.1f);
this.physicNode.setJumpSpeed(10);
this.physicNode.setMaxSlope( FastMath.PI / 2.0f );
//
// Place it at the correct position
//
physicNode.setPhysicsLocation( position );
faceDirection( direction.getX(), direction.getZ() );
}
[...]
// Add model
rootNode.attachChild( sceneChar.getSpatial() );
// Add control
CharacterControl control = sceneChar.getPhysicsControl();
physicsSpace.add( control );
[/java]
I tried to use a ForceCharacterControl instead of a CharacterControl. ( I havn't seen the difference )
It seems I will have to implement a collision listener to detect when there is a collision.
Can I have a small example of how to do that ? :)
Thanks in advance.
PS : I'm fairly new in implementing Physics.
Until now, I focused on the GUI part of my program.
So there may be something obvious for you guys that I didn't see.
PS2 :
Is my CharacterControl instanciation correct ? :)
Edit :
I just found this post : http://hub.jmonkeyengine.org/groups/physics/forum/topic/get-collision-of-charactercontrol/
Seems like its exactly what I am looking for... :D
I will try to use it,
This post has no more value then. I will close it after it try the solution given in the other post.
Just to be sure : Is the way I instanciate my CharacterControl correct ?