Ghost object not working right

Post Reply
Evan407
Posts: 22
Joined: Sun Jan 17, 2016 2:37 am

Ghost object not working right

Post by Evan407 »

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.

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());
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.
Evan407
Posts: 22
Joined: Sun Jan 17, 2016 2:37 am

Re: Ghost object not working right

Post by Evan407 »

I think maybe it had to do with collision flags

changing this

Code: Select all

	playerGhostObject.setCollisionFlags(CollisionFlags.NO_CONTACT_RESPONSE);
to this

Code: Select all

	playerGhostObject.setCollisionFlags(playerGhostObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE);
seemed to help.

http://stackoverflow.com/questions/5202 ... letphysics
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Ghost object not working right

Post by benelot »

I was looking at your question, but did not realize you did not keep the other flags. True, that is the problem. Can you mark your thread as solved by adding [SOLVED] to the beginning of the title of your first post? (Edit, add tag, save).
Post Reply