Physics model movement on user input, applyImpulse vs applyForce vs setPosition vs setLinearVelocity

playground #BCU1XR#1467 move with WASD

let me explain the what’s in the playground first.

  1. Physics Engine is applied

  2. In order to make a 3rd person camera, the hierarchy related to the dummy, dummy’s root, and the camera is as follow:
    | => dummy
    | => camera offset empty mesh
    | => ArcRotateCamera

    if I use setTarget at line 225 in the playground instead of camera.parent = the model will jiggle.

  3. action manager used to take keyboard input

Then here is my problem.
Which of the four methods mentioned in the title should I used for the movement?

setPosition is straight foward, calculated everything with current linear velocity and frametime,
but it makes me worried if it collides with other in the new position

setLinearVelocity, implemented in the playground, at line 268, or change the flag at line 64 tryImpulse to false.
The problem with it is that it doesn’t account for the “from rest to move” acceleration, or you could bake that into the code but it then runs into the same problem with impulse or force.

applyImpulse (implemented in playground) and applyForce, both are more or less the same, the major problem with these two methods is how do you deal with change in direction.
If you apply a constant force along the direction of the camera, it takes quite some time to eliminate the forward momentum in the origin direction, so you would need to set a higher magnitude when there’s a change in direction but, the first search come up with biomechanics is a research paper…

Is it the only way if I want to emulate a realistic athlete? Take everything into account, angular velocities, maximum force asserted by the legs to the ground, etc.

Thanks in advance.

Another option besides camera.parent = is camera.lockedTarget = . The jiggle from setTarget is maybe due to computeWorldMatrix(true) not being called in the Playground or Babylon source code. @Evgeni_Popov solved a similar question in ArcRotateCamera setting lockedTarget once vs. setting target every frame in scene.registerBeforeRender().

As you mentioned, perhaps you could use setLinearVelocity and pass in calculated velocities to simulate rest to move acceleration.


Thank you for telling more about the camera problem too!