- Home /
Smooth Camera (SmoothDamp) - force player to be in view/box
I have a Camera, and it updates its position as follows (just written this code, hope there is no bugs): Vector3 temp = (Player.transform.position - originalPlayerPos) + originalCameraPos; Vector3 newCameraPos = Vector3.SmoothDamp(prevCameraPos, newCameraPos, ref velocity, camSpeed); prevCameraPos = newCameraPos;
This works fine and follows the player. However, the problem is that if the player is falling (accelerates really fast), the camera's smooth damping cannot follow fast enough.
Of course, I could just force the "y" component of the newCameraPos not to use SmoothDamp, but then the vertical movement of the camera would be "clunky" and "jittery".
How do I fix this? I want smooth camera movement, but at the same time, I want the player not to fall outside of the camera when it's falling too fast (due to gravity).
I know there is a popular asset that fixes this in the asset store, but can I do it without this asset?
Thanks!