How to smoothly change position
In my game I want the camera to smoothly move to a certain position
float posY = Mathf.SmoothDamp(transform.position.y, player.transform.position.y + distToPlayer, ref velocity.y, smoothTimeY);
if(Input.GetMouseButton(0)|| player.transform.position.y > transform.position.y -2.6){
transform.position = new Vector3(transform.position.x, posY, transform.position.z);
}
In my script (attatched to camera), when the player position goes beyond the camera's the camera is meant to begin following it (script is in a fixed update), However the transition of the camera moving to follow the player is static and it just jumps to it. Is there a way I can make it seem smooth. Thanks
Answer by Zoogyburger · Mar 11, 2016 at 11:05 PM
Instead of saying
transform.position = new Vector3(
Try:
transform.position = Vector3.Lerp(
Lerped worked good, Had to play with some numbers but it did the trick.
if(Input.Get$$anonymous$$ouseButton(0)|| player.transform.position.y > transform.position.y -3){
Vector3 newPos = new Vector3(transform.position.x, posY, transform.position.z);
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * transitionSpeed);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612071439im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth speed increase while sprinting 0 Answers
Advanced placing position from the same angle of target position 0 Answers
Move a Rigidbody by a specific certain amount in a smooth motion? 2 Answers
How to compare limits for creating new objects in world space? 0 Answers
Lerp between two int vaules smoothly 4 Answers