0
\$\begingroup\$

I have two object to control and I wanted to keep them at cameras view without adjusting the cameras size but the camera can move only in positive y-axis meaning ones it goes up it shouldn't move down but it's okay if one object gets out of bounds. Since its 2D the camera is Orthographic view.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

If you can't make the camera view larger, then just set the camera's y position halfway between the two objects'

cameraY = (obj1Y +obj2Y) / 2

To make it stop at y = 0, use Mathf.Max:

cameraY = Mathf.Max(obj1Y + obj2Y, 0) / 2

This won't work if the camera can't display the two objects at once because they're too far apart

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.