Here are some basic examples i made for implementing a third-person camera. In order to avoid a stiff attachment to the player we can smoothly lerp the camera or camera rig to the goal to compensate quick motions.
First the more ideal dolly concept which respects the dolly distance, moving the camera dolly behind the player again even when not moving.
Dolly + goal
(use keyboard ASDW)
Fixed goal: https://codepen.io/Fyrestar/pen/zYqjNOL
This is the first example i made longer ago. As you see in some cases the camera will straight move over the player flipping to the other side as it is straight moving towards the goal.
Here is the dolly concept without goal. It basically is like just pulling a dolly behind you.
(use keyboard ASDW)
Dolly: https://codepen.io/Fyrestar/pen/WNwMWZV?editors=0010
I’ve seen this behaviour in some games, though i personally don’t like that you have to move further in order to pull the camera behind you again.
You can further adapt this also to avoid collisions with your scene, here is a very simple one using a raycaster from the player towards the dolly using the shorter distance if needed. But notice: this introduces the issue of the camera going straight towards the player again and will fail when the origin is inside the wall.
Dolly + goal + wall avoiding: https://codepen.io/Fyrestar/pen/ExKLZxd
To properly handle collisions a sphere collider should be used for the camera rather just a ray, in this case your dolly will be “pulled around the corner” and rotate. This can be done with a physics engine or a basic sphere collider.