ghost object doesnt detect collisions with kinematic objects

Post Reply
simejanko
Posts: 1
Joined: Fri Jan 03, 2014 7:13 pm

ghost object doesnt detect collisions with kinematic objects

Post by simejanko »

Hello! I am using jbullet, java port of bullet and i cant get my ghost object to detect collision with kinematic objects. The fact that it is a java port shouldnt matter too much since ive been working with c++ documentation all this time and didnt have any problem.

This is how i set up my ghost object:

Code: Select all

        CollisionShape ghostShape = new BoxShape(new Vector3f(0.2f,0.3f,0.2f));
	ghostObject = new GhostObject();
	ghostObject.setCollisionShape(ghostShape);
	ghostObject.setWorldTransform(new Transform(new Matrix4f(
                            new Quat4f(0, 0, 0, 1),
                            new Vector3f(1000, 401, 1000), 1.0f)));
        dynamicsWorld.addCollisionObject(ghostObject);
        dynamicsWorld.getBroadphase().getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback());	
	
	dynamicsWorld.setInternalTickCallback(new InternalTickCallback() {
			
        @Override
	public void internalTick(DynamicsWorld world, float timeStep) {
		for(int i=0;i<playerGhostObject.getNumOverlappingObjects();i++){
			RigidBody body = (RigidBody) playerGhostObject.getOverlappingObject(i);
			if(body.isKinematicObject()){
				System.out.println("Game over!");
			}
                        System.out.println("Collision");
		}
	}
}, this);
If i leave collision flags of an object that collides with ghost object unchanged (dynamic) or set it to static , the collision is detected.
Tried both

Code: Select all

santa.setCollisionFlags(santa.getCollisionFlags() | CollisionFlags.KINEMATIC_OBJECT);
and

Code: Select all

santa.setCollisionFlags(CollisionFlags.KINEMATIC_OBJECT);
I also disabled deactivation on my kinematic object.
Post Reply