I am working on a physics engine that uses basic Euler integration to compute forces. So, here is the thing:
function applyForce (rigidbody, force) {
rigidbody.forces.add(force);
}
function computeAcceleration (rigidbody) {
rigidbody.acceleration = rigidbody.forces / mass;
rigidbody.velocity = rigidbody.velocity + rigidbody.acceleration * time.deltaTime;
}
// The forces are reset after each gameloop
So now imagine I want to apply a force to jump, I will use applyForce
at the moment the player presses the jump button.
But: What happens is that the amount of movement depends on the gameloop speed, since the force is applied for a single frame. I feel like I missed something about how you should use forces, but I don't see how I should manage it properly.
In which cases should we use a force, considering this deltaTime issue? And also, what should I use instead?