Using btKinematicCharacterController, the movement is jerky

Post Reply
Teyn
Posts: 6
Joined: Wed Jan 07, 2015 10:13 am

Using btKinematicCharacterController, the movement is jerky

Post by Teyn »

Hi all. I was just trying to implement the btKinematicCharacterController for player movement, and here's the result: https://www.youtube.com/watch?v=Y5EMNxv96wI . As you can see, the movement is jerky, and jumping doesn't look natural.
Don't you know any potentional issue in my code?

Code: Select all

//all needed objects for world
        private btDiscreteDynamicsWorld world;
	private btCollisionConfiguration collisionConfig;
	private btDispatcher dispatcher;
	private btBroadphaseInterface broadphase;
	private btSequentialImpulseConstraintSolver solver;

// here's how I setup world
                collisionConfig = new btDefaultCollisionConfiguration();
		dispatcher = new btCollisionDispatcher(collisionConfig);
		broadphase = new btDbvtBroadphase();
		solver = new btSequentialImpulseConstraintSolver();
		world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig);
		world.setGravity(new Vector3(0, -9.81f, 0));

//here's how I setup the charController and add it into the world
private final btPairCachingGhostObject ghostObject;
	private final btConvexShape ghostShape;
	private final btKinematicCharacterController characterController;


                ghostObject = new btPairCachingGhostObject();
		ghostObject.setWorldTransform(instance.transform);
		ghostShape = new btCapsuleShape(0.5f, 0.5f);
		ghostObject.setCollisionShape(ghostShape);
		ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
		characterController = new btKinematicCharacterController(ghostObject, ghostShape, 0.35f);
		characterController.setUseGhostSweepTest(false);
		characterController.setUpInterpolate(true);
		
		world.addCollisionObject(ghostObject, (short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter,
				(short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
		world.addAction(characterController);

//and here's how I update it
		walkDirection.set(0, 0, 0);
		if (Gdx.input.isKeyPressed(Keys.W))
			walkDirection.add(1, 1, 1);
		else if (Gdx.input.isKeyPressed(Keys.S))
			walkDirection.add(-1, -1, -1);
		if (Gdx.input.isKeyJustPressed(Keys.SPACE))
			characterController.jump();
		walkDirection.scl(4f * delta);
		// And update the character controller
		characterController.setWalkDirection(walkDirection);

//and the world is updated like so:
world.stepSimulation(delta, 5, 1f/60f);
I would be very pleased if someone helped me. Thanks in advance!
Post Reply