In my game I use box2d objects and, as I understand it, you can move them only in two ways, SetLinearVelocity, and ApplyImpulse. I need to move the object 32 pixels in 1 turn. So I make a constant speed and the next problem appears. If the laptop is connected to the charge and gives 60 frames, the object begins to move faster. How do I make frameindependent movement? Without connection - 30 FPS and the game makes slowly.
I also know that if you want to be frameIndependent you need to use this formula:
x = x + speedPerSecond * secondsElapsedSinceLastFrame
But i cant use this formula, because i cant set box2d position. It is make box2d itself. I only can set the Velocity :( Or may me i just dont know.
2 - it is meters per second. 64 pixels.
private void handleInput(float delta) {
if (Gdx.input.isKeyPressed(Input.Keys.W)) {
b2body.setLinearVelocity(0, 2);
}
if (Gdx.input.isKeyPressed(Input.Keys.S)) {
b2body.setLinearVelocity(0,-2);
}
if (Gdx.input.isKeyPressed(Input.Keys.A)) {
b2body.setLinearVelocity(-2, 0);
}
if (Gdx.input.isKeyPressed(Input.Keys.D)) {
b2body.setLinearVelocity(2, 0);
}
}
How can i move object in another way or how to make movement frameindependent? SetTransform is not a good decision becasuse collisions are ignored. Thank You!