- Home /
Move Camera- Edge Of The Screen
Hello everyone, I have a question. My game is 2.5D platfrom game. When player presses "a" & "d" keys, my character moves to right or left it's alright. But I want to move my camera too, but I don't want camera to move at the same time with the character. When character gets closer to the right border of the screen, camera will move right. I want that. Like that:
if(Vector3.Distance(character.position,rightBorder)<5)
{
CameraMove();
}
So how can I detect the borders ?
Answer by Berenger · Jan 27, 2012 at 06:47 PM
You need a collider on the 2 dimensions of your game (use layers so it doesn't screw with the rest ), the use ViewportToRay, with (0, 0) and (1, 0) to get the world pos of each edge. Or the other way around ...
Your answer
![](https://koobas.hobune.stream/wayback/20220613063453im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to detect that an object (ball or disk) stays in between the tile and on the border of a tile? 1 Answer
Any help with prevent camera from passing a specific coordinate? 1 Answer
Shader Edges Transparent Relative to Camera 0 Answers
How to Calculate the border of Camera in Specific Depth? 0 Answers
Move the camera when the mouse reaches the edges of the screen 1 Answer