[solved] Laggy physics / Laggy camera

Hey,



I’ve ran into some issues with physics.

I’m using a character control for my local player, and when moving

the character seems to “jump” and have jagged movement,

even with high fps.



Been trying to troubleshoot, figuring out what might cause it.



Anyone have an idea why this might happen?



http://www.youtube.com/watch?v=6gY45fzPMfY

Not without seeing any movement code. The character walkDirection is already framerate decoupled, are you aware of that?

@normen said:
Not without seeing any movement code. The character walkDirection is already framerate decoupled, are you aware of that?


Right, so I can at least rule out it being caused by the rendering being unsynch with physics then.


I'm updating physics 60 times per second.
Here is how I do the movement.

[java]
private void handleMovement(float tpf) {
camDir.set(gs.cam.getDirection().getX(), 0, gs.cam.getDirection().getZ());
wDir.set(Vector3f.ZERO);
if ((input & 0xDF) > 0) {
camLeft.set(gs.cam.getLeft().getX(), 0, gs.cam.getLeft().getZ());
camDir.normalizeLocal();
camLeft.normalizeLocal();

if (PlayerCommand.LEFT.isActive(input)) {
wDir.addLocal(camLeft);
}
if (PlayerCommand.RIGHT.isActive(input)) {
wDir.addLocal(camLeft.negate());
}
if (PlayerCommand.FORWARD.isActive(input)) {
wDir.addLocal(camDir);
}
if (PlayerCommand.BACKWARD.isActive(input)) {
wDir.addLocal(camDir.negate());
}
if (PlayerCommand.JUMP.isActive(input)) {
jump();
}
setViewDirection(camDir);
wDir.normalizeLocal().multLocal(0.02f * player.getDefinition().getSpeed());
}
setWalkDirection(wDir);
}
[/java]

What do you mean by you are updating physics…?

@normen said:
What do you mean by *you* are updating physics..?


The physics update rate is 1/60, sorry for the bad wording.

I'm using bulletappstate.

Ok, as I could have guessed it was related to camera.



I had the updatePosition() of camera in the update method,

moving it to render method solved the “jumpy” feeling.

Hm… Thats not good. Use a Control to move the camera with the spatial that you attach later than the characterControl to the spatial.

1 Like

Aight I’ll try that.

Ah I see the order made the difference.

Previously I had the Control that handled camera initiated in the constructor of the characterControl, which makes it added before the character control itself.



After changing the structure getting the character control added first the issue was resolved.