- Home /
 
Creating a boundary that scales with orthographic camera
Cameras in Unity change the width of the scene displayed when using different aspect ratios. This makes it awkward when designing a game with kill boundaries off screen. To have them far enough away so they are off screen at 16:9, means when running at 4:3, their movement is not enough to take them as far as the boundaries.
I am looking for a way to make it so my death triggers are always just outside the camera viewport, whatever aspect ratio the player uses.
Can I attach a collider to an orthographic camera viewport?
In my initial testing, it would appear not, adding a BoxCollider2D works on the camera icon/centrepoint, and a BoxCollider doesn't attach to anything so is not dynamic.
Any advice on this one would be much appreaciated.
Answer by hexagonius · Nov 23, 2016 at 08:37 PM
it's just a little calculation you need to do to set this up dynamically. call ScreenToWorldPoint on your desired camera with the values 0,0.5f and 1,0.5f with the z value being the distance from the camera where your bounds should be. the result will be both side centers of the camera bounds. place your bounds with their respective half width offset there and there you go.
this works both, for orthographic and perspective. for the latter you would to take the depth of the bounds into account, because of the frustum angle. 
Your answer
 
             Follow this Question
Related Questions
Why Is My Orthographic Camera Not Rendering at the Full Resolution? 1 Answer
Prevent objects from disappearing when zooming in on an orthographic scene? 1 Answer
Setting Click and Drag constraints 2 Answers
Ortho camera viewport setup? 3 Answers
How to resize a camera's orthoSize for an object to fit inside its rect viewport? 1 Answer