- Home /
set Edge Collider 2D to the borders of the camera's viewport
hey im trying to set an edge collider to the border of the camer's view port so things won't just fly off the screen. I know i can just take 4 box coliiders but i want it to be able to adapt to the screen size and be a clean. here is what i have got so far: var rect = cam.rect; EdgeCollider2D col = GetComponent<EdgeCollider2D>(); transform.position = cam.ViewportToWorldPoint(new Vector3(1, 1, cam.nearClipPlane)) *cam.fieldOfView; Vector2[] points = new Vector2[5]; points[0] = new Vector2( 0, 0); points[1] = new Vector2(rect.xMax,0); points[2] = new Vector2(rect.xMax, rect.yMax); points[3] = new Vector2(0, rect.yMax); points[4] = new Vector2(0, 0); col.points = points;
Your answer
Follow this Question
Related Questions
TopDown local multiplayer camera edges collision? 1 Answer
Camera collision seeing through walls problem 0 Answers
Zoom camera to correct FoV based on Rect size 1 Answer
Lock the screen 1 Answer
Camera Shake 4 Answers