Objects not colliding well

I have two boxes:



[java]SphereCollisionShape capsuleShape = new SphereCollisionShape(1f);

player = new CharacterControl(capsuleShape, 0);

player.setPhysicsLocation(new Vector3f(0, 0, 0));

bulletAppState.getPhysicsSpace().add(player);

CollisionShape sceneShapeG = CollisionShapeFactory.createMeshShape(playerSpatial);

rigidBodyControl = new RigidBodyControl(sceneShapeG, 0);

playerSpatial.addControl(rigidBodyControl);

bulletAppState.getPhysicsSpace().add(player);

rigidBodyControl.setMass(1f);



player.setGravity(0);

player.setFallSpeed(0);



CollisionShape sceneShape2 = CollisionShapeFactory.createMeshShape(obstacle);

f = new RigidBodyControl(capsuleShape, 0);

obstacle.addControl(f);

bulletAppState.getPhysicsSpace().add(f);[/java]



I can move player, while f moves towards the player at a set speed. When I move towards f with player, the two collide well. However, if I wait until f approaches player, it passes right through it, and from then on they don’t collide. What’s the problem?

You cannot use mesh shapes for dynamic objects.

So what do I have to change from the code?

EDIT: This is how I move f:

[java]setup.f.setPhysicsLocation(new Vector3f(setup.f.getPhysicsLocation().x, setup.f.getPhysicsLocation().y, setup.f.getPhysicsLocation().z+0.02f));[/java]

Problem solved. Thanks @jamieeclipse for your post!



I only had to add this: [java]f.setKinematic(true);[/java]

No, the character and the floor will not collide properly. You can not use mesh shapes for dynamic objects. Use createDynamicMeshShape in the first call (which creates a hull shape instead) and make sure you only supply one geometry/mesh as compound shapes are not supported for characters. Or create the hull shape yourself using its geometry-constructor.

[java]SphereCollisionShape capsuleShape = new SphereCollisionShape(1f);

player = new CharacterControl(capsuleShape, 0);

player.setPhysicsLocation(new Vector3f(0, 0, 0));

bulletAppState.getPhysicsSpace().add(player);

CollisionShape sceneShapeG = CollisionShapeFactory.createDynamicMeshShape(playerSpatial);

rigidBodyControl = new RigidBodyControl(sceneShapeG, 0);

playerSpatial.addControl(rigidBodyControl);

bulletAppState.getPhysicsSpace().add(player);

rigidBodyControl.setMass(1f);



player.setGravity(0);

player.setFallSpeed(0);



CollisionShape sceneShape2 = CollisionShapeFactory.createMeshShape(obstacle);

f = new RigidBodyControl(capsuleShape, 0);

obstacle.addControl(f);

bulletAppState.getPhysicsSpace().add(f);

rigidBodyControl.setMass(1f);

f.setKinematic(true);[/java]



I did that, and everything runs fine. Collisions are well and good. I did not understand the problem :confused:



I also added a ground, and collisions are all well and good.

@normen, today I tested it again, adding gravity etc… and it worked perfectly. Is there something I am missing?

Huh? “Everything is working, am I missing something?” Whats that supposed to mean?

You said : “No, the character and the floor will not collide properly. You can not use mesh shapes for dynamic objects. Use createDynamicMeshShape in the first call (which creates a hull shape instead) and make sure you only supply one geometry/mesh as compound shapes are not supported for characters. Or create the hull shape yourself using its geometry-constructor.”

Yeah. You posted code and then said “I just have to add setKinematic” which would not fix the code you posted. The code you posted after that looks fine, as it does what I suggested. I know you know what you do but others that find this thread don’t :wink:

OK. Glad that’s settled. Happy New Year buddy :wink: Oh, and if you need any help with that video, just ask!