Camera Follow Help

Hey guys,

I am currently working on a camera follow for my video game and I am having issues with the camera staying in the upwards rotation of the plane. What I mean by this is that the plane is rotating around a gameobject(planet) and whenever the plane enters the bottom half of the planet the camera does not maintain the proper rotation to view the plane. I had tried using a Vector3 instead of the planes transform up and even a quaternion.lookrotation I can sense I am very close but cannot finagle my way around this issue.

My code:

public class PlayerController : MonoBehaviour
{  
    public Transform planeMesh;

    // Update is called once per frame
    void Update()
    {
        CameraFollow();
    }

    void CameraFollow()
    {
        Vector3 moveCamTo = planeMesh.position - planeMesh.forward * 5.0f + planeMesh.transform.up * 3.0f;
        float bias = 0.96f;
        Camera.main.transform.position = Camera.main.transform.position * bias + moveCamTo * (1.0f-bias);
        //Camera.main.transform.rotation = Quaternion.LookRotation(planeMesh.position + planeMesh.forward * 1.0f, planeMesh.transform.up);
        Camera.main.transform.LookAt(planeMesh.position + planeMesh.forward * 1.0f);
    }
}

LookAt takes two parameters. The second parameter defaults to Vector3.up, but you should probably pay attention to it in your case since Vector3.up will not be appropriate for you when on the sides or bottom of your planet:

1 Like

Wow such a simple mistake, thank you so much i appreciate the help!! making the lookat transform.up worked perfectly