Movement speed of the character

[java] long lastTime = System.currentTimeMillis();

@Override

public void simpleUpdate(float tpf) {

if (lastTime + 1000 < System.currentTimeMillis()) {

System.out.println(character.getPhysicsLocation() + " - speed: " + speed + " - tpf: " + tpf);

lastTime = System.currentTimeMillis();

}

character.setWalkDirection(new Vector3f(30, 0, 0).multLocal(tpf));[/java]



Why does this codes works with a 60 fps, but it doesn’t work with a 600 fps game?



Output for 600 fps

(77.50421, 5.0006723, 0.0) - speed: 1.0 - tpf: 0.0016562501

(80.577446, 5.0004244, 0.0) - speed: 1.0 - tpf: 0.0017187501

(83.64035, 5.004261, 0.0) - speed: 1.0 - tpf: 0.0016562501

(86.64233, 5.004313, 0.0) - speed: 1.0 - tpf: 0.0016562501

(89.652756, 5.0037932, 0.0) - speed: 1.0 - tpf: 0.0016562501

(92.26379, 5.0024548, 0.0) - speed: 1.0 - tpf: 0.016666668

(95.17605, 5.0000005, 0.0) - speed: 1.0 - tpf: 0.016666668

(98.82231, 5.000313, 0.0) - speed: 1.0 - tpf: 0.0018750001

(101.96773, 5.001317, 0.0) - speed: 1.0 - tpf: 0.0016562501

(104.97157, 5.0049696, 0.0) - speed: 1.0 - tpf: 0.0016562501

(107.990395, 5.000001, 0.0) - speed: 1.0 - tpf: 0.001625



Output for 60 fps

(111.46693, 5.005535, 0.0) - speed: 1.0 - tpf: 0.016656252

(141.9704, 5.0000706, 0.0) - speed: 1.0 - tpf: 0.016656252

(172.43382, 5.0, 0.0) - speed: 1.0 - tpf: 0.016656252

(202.93192, 5.0029716, 0.0) - speed: 1.0 - tpf: 0.016656252

(233.43193, 5.000001, 0.0) - speed: 1.0 - tpf: 0.016687501

(263.43225, 5.0, 0.0) - speed: 1.0 - tpf: 0.016687501

(293.93286, 5.0, 0.0) - speed: 1.0 - tpf: 0.016656252

(324.43256, 5.0, 0.0) - speed: 1.0 - tpf: 0.016656252

(354.93134, 5.000001, 0.0) - speed: 1.0 - tpf: 0.016687501

(385.42798, 5.0, 0.0) - speed: 1.0 - tpf: 0.016656252

For some reason I find this very funny. :smiley:

Sorry, I’m kinda drunk atm, so I messed up things a bit.

tpf = time per frame (iirc, it means the time it has taken to go through the last frame, but don’t quote me on that one).



So, technically, if you’re running more frames per second, the number will be smaller.



Also, technically, by using whatever constant (speed, rotation, movement) multiplied by tpf, you’re actually making the whole thing “frame-independent”. In short, it should move/rotate/etc at a constant speed regardless of FPS.



Hopefully that’s what you wanted to know.

No, because I knew that it should be frame independent, but when running the same code, I get different outputs for VSync On and VSync off :confused: I should have 30 meters / second on both cases, but I’m getting 3m/s in a 600 fps system.



Edit: My update method ends there!

The walk direction of the character is frame rate independent already. :roll:

1 Like