- Edited
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?