Camera target.set(...) causing world shake/jittering

I have a car moving on a road and the camera is updating its position and target to look at the car as it moves.

I am getting the strangest world shake/jittering.

cameraOrbitControls.object.position.set(cameraPosX, cameraPosY, cameraPosZ)

cameraOrbitControls.target.set(carNewPosition.x, carNewPosition.y, carNewPosition.z)

However, i have narrowed the problem down to the camera target.set() call. When i remove this line the problem goes away, but its obviously not tracking the car how i would like anymore.

cameraOrbitControls.object.position.set(cameraPosX, cameraPosY, cameraPosZ)

// cameraOrbitControls.target.set(carNewPosition.x, carNewPosition.y, carNewPosition.z)

It feels like there is some bad matrix multiplication going on in target.set(…). Can anyone please explain this strange behavior?

(yes i have logarithmicDepthBuffer enabled, and updating camera controls in main loop)

Are you sure the OrbitControls is the right option for this setup?

If so, call cameraOrbitControls.update() each time the target or position of camera is changed.

Yes i believe OrbitControls is the right option and performs how i expect, except for this unintended jitter. I added additional update()'s to satisfy when the car’s position is updated as well, the jitter remains.

Sorry, then a skeleton demo presenting the problem is required to prevent guessing war.

I’ve researched problems similar to mine and never heard of a “Skeleton Demo” being requested, and im not sure how the skeleton will help you as the problem appears to be related to the manipulation of camera matrices. Based on the footage im wondering if anyone has experienced something similar or can point me in the right direction.

I once got a similar problem, and it was because I was calling renderer.render(scene, camera) in a different node tick instead of sequentially after updating my camera

1 Like

Yup @Sceat that’s a good hypothesis.

@CanadianShawn

You can refactor like this:
camera.position.set(cameraPosX, cameraPosY, cameraPosZ);
cameraOrbitControls.target.copy(carNewPosition)
…
cameraOrbitControls.update();
renderer.render()

You want to … Update camera.position, and controls.target…then call controls.update()
then call renderer.render() in that order, all in the same frame.