- Home /
How do I make the camera stay on a fixed Z-pos where it moves X/Y delayed from the player object?
I am trying to make a player object that moves forward (or sideways) and to give the sense of "smooth movement" I am trying to damper the camera movements so the cameras position follows the main object, but delayed.
Both objects. Main/player object and camera have their own Z-pos. When player goes up (Y) or left (X) the camera already keeps the player in focus with smoothfollow target.
But I am trying to get the camera to move in "behind" the player after a while, sort of damping within 1-2 seconds.
That is, if we go in a streight forward, the camera positions itself behind player over time.
Initial positions:
left ----------------- player x-pos ----------------- right
^ LookAt(main) ^
left ----------------- camera x-pos ----------------- right
.....then player moves left on X-axis:
left ------ player x-pos ---------------------------- right
^ LookAt(main) ^
left ----------------- camera x-pos ----------------- right
after a second or something camera follows:
left ------ player x-pos ---------------------------- right
^ LookAt(main) ^
left ------ camera x-pos ---------------------------- right
I have the camera following with dampered LookAt now, but I cant figure out which formular to make the camera position dampered too?
Any suggestions?
I am already using this for LookAtTarget
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
Your answer
Follow this Question
Related Questions
Rotate Camera in Increments with Damping 2 Answers
Damping the rotation of a camera that is attached to an object. 1 Answer
Jittery objects when camera attached to rigidbody 6 Answers
iTween's inaccuracy of final position 2 Answers
Camera Dampening 0 Answers