- Home /
How to restrict camera movemetn alaong the y axsis?
Hello,
I am trying to create a smooth camera movement script. I have been able to get the smooth movement that I wanted but the gameobject that the camera follows moves forwards as well as bounces up and down. I only want the camera to follow the gameobject when it is moving forwards and not when the gameobject is bouncing. I am looking for a way to have it where I can restrict the movent of the camera along the x-axis. Here is the script that is on the camera
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
private void FixedUpdate()
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
}
If anybody has any suggestion stat would be great!
Thanks!
Answer by IAmChiagozie · Jul 08, 2019 at 03:40 AM
Cinemachine will work perfectly. Furthermore, camera movements should be done on void LateUpdate and not void FixedUpdate
Answer by unityJe · Jul 07, 2019 at 08:46 PM
Hi,
Have you tried using cinemachine? It's free from the package manager, and easy to use. There are lots of tutorials on youtube about how to use it. Setting it up to do this should be easy.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
transformDirection for camera control 1 Answer
Confining Mouse Look on X axis 0 Answers