Hi all,
I’m a long-time Java user but a first-time JME user, so please be patient with me if my question seems naive. I am running The JM 3.0 SDK on Linux Mint. I am aware that CharacterControl is deprecated, but sources elsewhere on the forums told me that BetterCharacterControl is still buggy and not ready for use.
My problem is with the CharacterControl class- it seems to be scaling the character’s movement speed with FPS, but not properly. In the update function of CharacterControl (the code for which is included at the end of this post), I call setWalkingDirection() and pass it a normalized vector representing the direction of the camera. I then use CharacterControl.getPhysicsLocation() and cam.setLocation() to sync the camera with the CharacterControl.
At 60 FPS, this works exactly as one would expect- walkingDirection is set to 1 unit (because I normalized the vector), and the physicsLocation is moved forward 1 unit per frame. However, at 5 FPS, the physicsLocation is moved forward 4 units per frame, though the walkingDirection is still set to 1 unit. I suspect that bullet physics manages framerate independence internally, however 5 FPS is 1/8 of 60 FPS, so the physicsLocation should move forward 8 units per frame, not 4.
I tried tracing JMonkey’s sourcecode for the cause of the conflict, but I got lost somewhere in the JBullet’s many native calls. Any guidance would be greatly appreciated. Let me know if you need more information (or less, as I can be confusingly wordy)
Thanks!
-Eihiko
Code (only allows for forward movement, for simplicity’s sake):
[java]
public void update(float tpf){
//Create a unit vector in the direction of the camera.
camDir.set(cam.getDirection());
camDir.setY(0);
camDir.normalizeLocal();
//Reset the walkDirection for this frame.
walkDirection.set(0,0,0);
//If the user hits the up arrow, set the walkDirection 1 unit in the direction of the camera.
if(up){
walkDirection.addLocal(camDir);
}
// Set the walk direction
ctrl.setWalkDirection(walkDirection);
// Sync the camera to CharacterControl
cam.setLocation(ctrl.getPhysicsLocation());
}
[/java]