- Home /
TopDown local multiplayer camera edges collision?
Hi,
I'm working on a local multiplayer top down shooter. Currently I have the camera zoom out as the players move further away from each other, what I want is the players to collide with edges of the screen but can't figure out how. So let's say player one is on the center of the screen and player 2 is walking towards the edge of the camera, the camera would follow player 2 until player 1 is on the edge and then stop player 2 from walking any further away. Hope you get what I mean. I have searched everywhere and couldn't find any answers, tried with colliders attached to player 1 or camera but that would just drag other players when they get to the edge :( Please help
Answer by stuey0016 · Jan 06, 2019 at 06:03 PM
@pbiesek92 I'm wondering if you could use Camera.WorldToViewportPoint(Vector3) for this problem?
This returns a vector where the x and y components represent the screen position relative to the camera rendering the screen. If this returns values really close to 1 or 0, you'd know the players are close to the edge of the screen (and therefore you could artificially stop them from moving farther in that direction).
Your answer
![](https://koobas.hobune.stream/wayback/20220612175939im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
New Input Manager Split Screen and Cinemachine 0 Answers
Local Multiplayer Camera 0 Answers
set Edge Collider 2D to the borders of the camera's viewport 0 Answers
Local Mulitplayer 2d Camera 0 Answers