CharacterControl movement not scaling with FPS

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)


Code (only allows for forward movement, for simplicity’s sake):

public void update(float tpf){
//Create a unit vector in the direction of the camera.
//Reset the walkDirection for this frame.
//If the user hits the up arrow, set the walkDirection 1 unit in the direction of the camera.
// Set the walk direction
// Sync the camera to CharacterControl

Look at the setMaxSubSteps javadoc of the PhysicsSpace, at 5 fps you will have to raise it.

Thanks, Normen! Is it safe to assume that anything related to bullet will automatically be scaled with FPS and that for anything outside of bullet, I will have to use tpf to scale it?

Thanks, that answers my question! (To future readers who may not be ready to read the entire physics tutorial yet: yes, bullet does handle FPS by default. I couldn’t find out which other parts of JMonkey automatically handle FPS though, so I’ll assume bullet is the only part.)

I’ll mark this as resolved as soon as I figure out how.