Ghost object not working right
Posted: Sat May 28, 2016 2:57 am
I have a ghost object that goes on a player object to detect collisions. For some reason the ghost object isn't detecting collisions properly even though I set it to have the same transform every tick and the same collision shape. The normal player rigid body hits the ground at his feet but the ghost object has a collision at least 5 meters over the ground.
The player and the ghost have the exact same origin and collision shape but the ghost is detecting collisions when it shouldn't like its Y axis position is off or something.
Code: Select all
playerGhostObject = new GhostObject();
playerGhostObject.setCollisionShape(playerShape);
playerGhostObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT);
dynamicsWorld.addCollisionObject(playerGhostObject,(short)(0x04),(short)(0x01 | 0x02));
dynamicsWorld.addRigidBody(playerRigidBody,(short)(0x05),(short)(0x01 | 0x02));
dynamicsWorld.getPairCache().setInternalGhostPairCallback(new GhostPairCallback());//needed
Code: Select all
//player movement
dynamicsWorld.setInternalTickCallback(new InternalTickCallback(){
@Override
public void internalTick(DynamicsWorld world, float timeStep){
playerRigidBody.setLinearVelocity(new Vector3f(Inputs.playerX_Velocity,playerRigidBody.getLinearVelocity(new Vector3f()).y,0));//z axis locked for side scroller
playerGhostObject.setWorldTransform(playerRigidBody.getWorldTransform(new Transform()));
}
}, dynamicsWorld.getWorldUserInfo());