Zooming out and keeping the map centered

BagzliBagzli Member, PRO Posts: 48

Hello,

I am trying to zoom out the map to show the whole map and keep it centre. Since I am dealing with a large number of maps and they all differ in sizes, I need to make things a bit more dynamic.

Right now, I interpolate camera to x and y size which makes the map zoom out and it works great. However, if the map is taller than it is wider, there is more extra space in the width. When there is this extra space, the map is moved to the left side and it leaves a gap of empty space on the right.

I am trying to figure out how to interpolate camera to zoom out and at the same time keep it centred. I am fairly sure that I need to Interpolate or Constrain Camera Origin as I interpolate Camera Size, however I cannot figure out a formula that would keep it centred when zoomed out and not affect camera when completely zoomed in.

Has anyone encountered this before and if so what formula have you used to keep the map centred while zoomed out?

Comments

  • BagzliBagzli Member, PRO Posts: 48

    I figured it out.

    My problem is that I was creating a camera object and telling the camera to follow the object which was messing with the origin whenever I set it. To solve it, I have interpolated camera size to what I need and then told the origin to adjust itself based on width or height, depending on which one is larger.

Sign In or Register to comment.