Hi, I have a object resizing itself.

When I focus the object with MoveCameraTo its working fine.

But when I try to do the same in 1 frame, it changes to a wrong distance.

Basicly what I use is this function:

public void focusCamera(bool instantSwitch, Vector3 direction, Vector3 upwards, float offsetX = 0, float offsetY = 0, float offsetZ = 0)
    {
        Vector3 targetPostion = new Vector3(fundament.GetComponent<Renderer>().bounds.center.x + offsetX, fundament.GetComponent<Renderer>().bounds.center.y + offsetY, fundament.GetComponent<Renderer>().bounds.center.z + offsetZ);
        float targetDistance = 20f;
        Quaternion targetRotation = Quaternion.LookRotation(direction, upwards);
        if (instantSwitch)
        {
            if (CoroutineUnlockCam != null)
            {
                StopCoroutine(CoroutineUnlockCam);
            }
            CameraPerspective.MoveCameraToInstant(targetPostion, targetDistance, targetRotation);
        }
        else
        {
            CameraEvents.OnRequestObjectFollow?.Invoke(modelBase, true, false);

            CameraPerspective.MoveCameraTo(targetPostion, targetDistance, targetRotation);
            //camMode = cameraMode.Free;
            if (CoroutineUnlockCam != null)
            {
                StopCoroutine(CoroutineUnlockCam);
            }
            CoroutineUnlockCam = StartCoroutine(unlockCam());
        }
    }

    IEnumerator unlockCam()
    {
        yield return new WaitForSeconds(2.0f);
        CameraEvents.OnRequestObjectFollow?.Invoke(modelBase, false, false);
    }

What am I doing wrong please?

    Hi,
    The first thing I noticed is that your are calling
    CameraEvents.OnRequestObjectFollow?.Invoke
    at the same time as
    CameraPerspective.MoveCameraTo(

    these two things will modify the camera at the same time, you should only call one of them.
    This could be why you don't get the same end result.

      but thats the part, what is working fine ...

        Masegi did you have a look at the "move camera" demo scene?

          yes but i only see pink squares cause auf urp. cant u just fix my function? otherwise just refund

            I now tried this one

            
                public void focusCamera(bool instantSwitch, Vector3 direction, Vector3 upwards, float offsetX = 0, float offsetY = 0, float offsetZ = 0)
                {
                    //instantSwitch = false;
                    Vector3 targetPostion = new Vector3(fundament.GetComponent<Renderer>().bounds.center.x + offsetX, fundament.GetComponent<Renderer>().bounds.center.y + offsetY, fundament.GetComponent<Renderer>().bounds.center.z + offsetZ);
                    float targetDistance = 20f;
                    Quaternion targetRotation = Quaternion.LookRotation(direction, upwards);
                    CameraPerspective.FocusCameraOnGameObject(modelBase, true);
                    if (instantSwitch)
                    {
                        //if (CoroutineUnlockCam != null)
                        //{
                        //    StopCoroutine(CoroutineUnlockCam);
                        //}
                        CameraPerspective.MoveCameraToInstant(targetPostion, targetDistance, targetRotation);
                    }
                    else
                    {
                        //CameraPerspective.FocusCameraOnGameObject(modelBase, true);
                        //CameraEvents.OnRequestObjectFollow?.Invoke(modelBase, true, false);
            
                        CameraPerspective.MoveCameraTo(targetPostion, targetDistance, targetRotation);
                        //camMode = cameraMode.Free;
                        //if (CoroutineUnlockCam != null)
                        //{
                        //    StopCoroutine(CoroutineUnlockCam);
                        //}
                        //CoroutineUnlockCam = StartCoroutine(unlockCam());
                    }
                }

            But now I get transform.position assign attempt for 'TouchCamera' is not valid. Input position is { NaN, NaN, NaN }.

              Masegi Hi
              You cannot call both
              CameraPerspective.FocusCameraOnGameObject(modelBase, true);
              And MoveCameraTo() at the same time. It's either you choose to focus on a game object, OR you move the camera to a specific location/ rotation manually.

              Please look at the example scenes. You can switch to Built-in RP real quick if needed.

                Write a Reply...