1

I have a ball which we can throw here and there in my game. I want my cinemachine vcam to move only in the x direction with the ball. And just look up to the ball while its in air. I don't want the camera to move in y direction along it too.

I have set the look at and follow fields to the ball only. All i want it the camera to not follow the ball in y. (Basically, follow the ball in x, and keep looking at it in the air)

How can I achieve this is the most trivial and beautiful way possible? (open to scripts, but the lesser code the better)

Dhruv Chadha
  • 1,161
  • 2
  • 11
  • 33

1 Answers1

0

as i've just tested, You can write a script that attaches to your camera, where you create a new vector3 with the x of your ball, and the frozen Y values that you want here's an exemple: public class CameraController : MonoBehaviour

{
    //Assign your ball in the inspector
    public Transform target;

    // Update is called once per frame
    void Update()
    {
        //Here i assumed that you want to change the X 
        Vector3 newCamPosition = new Vector3(target.position.x, yourValue, yourValue);
        gameObject.transform.position = newCamPosition;
    }
}

Hope It helped <3