ArcRotateCamera setting lockedTarget once vs. setting target every frame in scene.registerBeforeRender()

Hi all! Noticed that setting the target of ArcRotateCamera every frame in scene.registerBeforeRender(), the player’s mesh experiences “abrupt” movement. When replacing this with setting lockedTarget just once, the movement became smooth. Could you please view the Playgrounds below, and I would be grateful for any insight on this.

In case the GIF’s below are unclear:

For the Playgrounds below:
Please click inside the Playground’s scene to activate pointer lock
WASD: Movement

1. Playground setting lockedTarget once - smooth movement :smiley: :

camera.lockedTarget = cameraTargetMesh;


2. Playground setting target every frame in scene.registerBeforeRender() - abrupt movement :cry: :

scene.registerBeforeRender(() => {
    // Update camera target
    const cameraTargetMeshOffsetPosition = cameraTargetMesh.getAbsolutePosition();;

    // Player move

I think I’m misunderstanding how position updates are handled and would be thankful if anyone could shed some light on this. Thank you for your help! :smiley:

1 Like

You need to:

  • set the camera target after you compute the new player position, as it depends on it
  • explicitely update the world matrix of the player / target mesh before getting the target mesh position. The world matrix computation is normally done by the system, but later in the process.


Mindblown! Thank you so much, @Evgeni_Popov! :smiley_cat: