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);