- Home /
Zooming camera using move z position.
Hello i want to zooming camera using Lerp in orderto move camera in Z axis. why don't use field of view?? Because my GUI is 3d plane that stick together with the camera when change fov the position and scale of GUI with wrong too. it happed that it doesn't move at all when lerp. i don't know why .
here is my code.
private IEnumerator ZoomINOut()
{
while(true)
{
if(isZoomed == true)
{
//zoomIN();
zoomIN_2();
}
else
{
// zoomOUT();
zoomOUT_2();
}
yield return null;
}
}
public void zoomIN_2()
{
Debug.Log("ZoomIN_2");
Vector3 current = cameraTrans.position;
cameraTrans.localPosition = new Vector3(current.x, current.y, Mathf.Lerp(-20, -12, Time.time));
}
public void zoomOUT_2()
{
Debug.Log("ZoomOUT_2");
Vector3 current = cameraTrans.position;
cameraTrans.localPosition = new Vector3(current.x, current.y, Mathf.Lerp(-12, -20, Time.time));
}
but when use zoomOUT(); and zoomIN(); it works well but it's not what i want since i want to move z axis instead of changing FOV.
public void zoomOUT()
{
Debug.Log("ZoomOUT");
cmra.fieldOfView = Mathf.Lerp(cmra.fieldOfView,zoomOut,Time.deltaTime*smooth);
}
public void zoomIN()
{
Debug.Log("ZoomIN");
cmra.fieldOfView = Mathf.Lerp(cmra.fieldOfView,zoomIn,Time.deltaTime*smooth);
}
Comment
i have try fix it to
cameraTrans.localPosition = new Vector3(current.x, current.y, $$anonymous$$athf.Lerp(current.z, -12, Time.deltaTime*smooth));
but still doesn't work