Math help dealing with orthographic camera bounds and pinch zoom
The math is making my head hurt tonight. Ortho camera, defaulting to a 3.84 size. I have pinch and zoom and boundaries set already. When the camera zooms in, the ortho size can go down to 1.5. Now my x boundary on the right for example is normally 0.35f.. thats as far over as I want it to move. When it's zoomed in, the right boundary becomes 4.5. But how on earth can I convert that 0.35 to 4.5, or some fraction of when the camera is zoomed? the numbers are just eluding me.
I'm confused, can you draw me a pretty picture in paint? Thanks.
Lol.. not even sure how to do a pic on that.. camera $$anonymous$$AX x should be 0.35 when zoomed OUT.. thats an ortho size 3.84.. so you zoom in, ortho size shrinks to say 1.5.. which means my new max X bound would be 4.5 for the same spot. Not sure if that helps, so as the ortho size decreases, how do i change my 0.35 to the appropriate value.. basically when zoomed in, the camera needs to move further to get to that right edge.. but thats the part i cant figure out. i know the beginning and end, but how do i dynamically calculate that..
Answer by SquigglyFrog · Dec 27, 2015 at 03:40 AM
Actually, i think my brain just kicked into gear.. if I use this
float maxX = (origCamScale - cam.orthographicSize) * 2;
camPos.x = Mathf.Clamp(camPos.x, -maxX, maxX);
voilà!
That works and I dont need to worry about the 0.35.. nevermind.. staring at it for hours probably killed me..
hey, I'm also having the same problem. Can you help me with it. What is origCamScale here? Like yours my head is also getting hurt thinking about his problem.