playMaker

Author Topic: Edge Clamping on Orthographic Camera Zoom[SOLVED]  (Read 3856 times)

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Edge Clamping on Orthographic Camera Zoom[SOLVED]
« on: January 18, 2016, 09:42:07 PM »
Hello again! I spent the weekend trying to set up a camera, and even got most of the way to an implementation I was looking for. The camera averaged between targets, and lerped at a comfortable speed between its current and updating positions based on the player and enemy locations. I started to look up orthographic zooming documentation when I found an Smash Bros style, multitarget, zooming camera in Ecosphere. It was a breeze to implement, and I'd love to thank whomever made it but I can't seem to find an attribution.

Anyway my actual question is how do I clamp the lower bounds of the camera view to prevent a bunch of empty space from appearing on the screen? I tried placing childed target objects on the characters that I could position on the screen but that only helps for either extreme of zoom in/out and causes a different positioning problem elsewhere.

Basically this is what I have currently.

Current Zoom In
http://imgur.com/UwFDSRN

Current Zoom Out
http://imgur.com/LnfRran


And this is what I would like to achieve.

Preferred Zoom In
http://imgur.com/GYCrCnI

Preferred Zoom Out
http://imgur.com/NyJQjkf

I'd like to keep the tiles close to the bottom of the screen and have the screen zoom out and up, rather than just universally out.

My current running theory would be that I either need a target object like I currently have, but give it the ability to move up and down on the Y axis based on player distance, OR find a way to clamp the lower bounds of the camera to a specific area of the screen.

Any suggestions or ideas?
« Last Edit: January 21, 2016, 10:15:36 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Edge Clamping on Orthographic Camera Zoom
« Reply #1 on: January 19, 2016, 07:54:43 AM »
Hi,

 The trick is to understand that the orthographicSize is linked to the vertical units in the Unity world.

http://docs.unity3d.ru/ScriptReference/Camera-orthographicSize.html

so, if the orthographicSize is 10, then from the bottom to the top of the screen, you'll have exactly 20 units.

You can then deduce how much you need of camera movement vertically to reach a given position.

let say the bottom of the screen should tangent with a sprite who's bottom is located at -10 units.

you set the orthographic size to 5, and are guaranteed to have the bottom of this sprite exactly at the bottom of the screen.

Does that make sense?

now if you introduce zooming ( changing the orhtosize), you need to counter effect this by moving the camera up and down accordingly.

I made a sample on the Ecosystem 'SpriteFitAndClamp' to demonstrate the above:

https://twitter.com/JeanAtPlayMaker/status/689427981635162113



This includes as well some actions I did yesterday on fitting/filling sprites and given sizes within the screen.

https://twitter.com/JeanAtPlayMaker/status/689054364275740673

https://twitter.com/JeanAtPlayMaker/status/689054364275740673

Bye,

 Jean

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Edge Clamping on Orthographic Camera Zoom
« Reply #2 on: January 19, 2016, 09:59:24 PM »
I think it makes sense jeanfabre. The orographic size is half the actual size on the screen, and if I'm zooming in by say 50 units, then I would want to shift the camera up by 25 units. Or would it be 100? Either way I think I might have enough to go on!

Thank you, I'll let you know how it goes!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Edge Clamping on Orthographic Camera Zoom
« Reply #3 on: January 20, 2016, 01:07:56 AM »
Hi,

You would then move the camera up 25 Units.

 experiment directly with Unity Editor, you can toy around with the values without any logic implemented, and see the results. This is how I worked it out. Make a quad of 10*10 and then experiment, both looking at the scene view and the game view, you'll see exactly how things interact with each other.

 The sample provided has the maths in plain sight within the state, there is no dedicated action to move the camera to clamp the bottom target, so you can also experiment with that fsm, and of course try to reproduce it from scratch ( the ideal way to learn and assimilate).

Bye,

 Jean