- Home /
How can I get the lowest position of objects that are visible by the camera?
I am making a platform game, and I have a collider underneath the platforms that triggers a death animation. I would like the height of this collider to be re-positioned as time goes on so that it matches the lowest visible platform. Any ideas?
Answer by supernat · Mar 19, 2014 at 05:58 PM
It would go something like this. Loop through all platforms, test their transform position plus their bounds to find the maximum distance in your left/right direction. Get the points on the left/right side of screen where the camera's view frustum intersects the objects (i.e. use some trigonometry to cast a ray from the camera's position along its view frustum wall (which is conveniently an angle of half of the FOV) to find the world position in the same plane as your platforms. If the platform is currently visible in your view, determine the maximum DOWN distance from the platform (using its bounds). Now add some fudge factor just below that for the death area. In the next iteration, check if the current platform is lower than the death area and adjust the death area as needed. Optimally, you would just keep a single Y value through the loop that is only allowed to go down, then set the death area's position to that Y value (assuming you are using Y for up).
Your answer
Follow this Question
Related Questions
2.5D Platformer Camera 1 Answer
2d camera movement 1 Answer
Rotate Camera 1 Answer
3d platforming Camera 1 Answer
Rotate camera with player 1 Answer