Daniel Lip
Daniel Lip

Reputation: 11321

How can I reposition the camera automatic to include in the view the whole object?

Now the bottom is a bit missing so I'm moving on my own the Robo Camera a bit back so Z is at position 0.140

In the original when it's reposition the camera automatic Z is at : 0.1295914

This is the script I'm using to reposition the camera :

public void ActivateRoboSphere()
    {
        foreach (Transform child in transform)
        {
            if (child.name == "Robo Camera")
            {
                RepositionCamera(child);
                roboCam = child.GetComponent<Camera>();
            }
        }

        anim = GetComponent<Animator>();
        anim.enabled = true;

        GetComponent<FPEInteractableActivateScript>().interactionString = "";
        FPEInteractionManagerScript.Instance.BeginCutscene();

        StartCoroutine(PlayAudio());
    }

    private void RepositionCamera(Transform camera)
    {
        var Eyes = GameObject.Find("eyeDome");
        camera.position = Eyes.transform.position + Eyes.transform.forward;
        camera.LookAt(Eyes.transform);
        camera.GetComponent<Camera>().enabled = true;
    }

The result is :

When reposition the camera automatic

And this is after I set the Z to 0.140

Moved back to 0.140

Because I'm using this robot in other places also in my scene I want that automatic it will reposition the camera. I can set the Z to be always 0.140 but that is also depending on where I will position the Robot it self in other places. I just wonder if there is a way to do it automatic for all the places.

Upvotes: 1

Views: 63

Answers (1)

MoonMadnesS
MoonMadnesS

Reputation: 73

when Camera is looking at the Eyes object they have opposite forward values, you can reposition camera After changing its rotation. something like this maybe ?

    private void RepositionCamera(Transform camera)
{
    var Eyes = GameObject.Find("eyeDome");
    camera.position = Eyes.transform.position + Eyes.transform.forward;
    camera.LookAt(Eyes.transform);
    camera.postion -= new Vector3(0,0,0.140f);
    camera.GetComponent<Camera>().enabled = true;
}

Upvotes: 1

Related Questions