Quantcast
Viewing all articles
Browse latest Browse all 2891

Position is infinite

Hey, I'm trying to make a CameraZoomScript that makes it so that if I zoom in or out, the lower left corner stays exactly at 0, 0, 0. Since the camera has no adjustable pivot point I know of (please, correct me if I'm wrong) I have to calculate what the camera position should be as it grows in size. My solution for this is the following code. void KeepCameraCentered() { if (sizeLastFrame < mainCamera.orthographicSize || sizeLastFrame > mainCamera.orthographicSize) { float newX = (transform.position.x / sizeLastFrame) * mainCamera.orthographicSize; float newY = (transform.position.y / sizeLastFrame) * mainCamera.orthographicSize; transform.position = new Vector3(newX, newY, transform.position.z); } sizeLastFrame = mainCamera.orthographicSize; } The problem is not that it doesn't work. This works perfectly fine for me but my problem is that I get this annoying error when I run the game in Unity Editor. transform.position assign attempt for 'Main Camera' is not valid. Input position is { Infinity, Infinity, -10.000000 }. UnityEngine.Transform:set_position(Vector3) PinchZoom:KeepCameraCentered() (at Assets/PinchZoom.cs:72) PinchZoom:Update() (at Assets/PinchZoom.cs:29) So my question is: Should I just ignore this error since everything seems to be working or should I fix it, and if the latter, how can I fix it. If you want to help but need some more info, please ask for what you need and I will do my best to help you help me ;).

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>