- Home /
How to keep player in screen?
Hey, I'm using Unity in 2D, but I can't seem to find a way to keep the player from going off the screen.
Now I have an idea on how to maybe implement this. Would I need to check the player position against the camera position?
any help would be appreciated. Thanks.
Answer by ikelaiah · Apr 08, 2014 at 10:38 PM
You can match the horizontal and vertical direction of the character to the camera, like this explanation by @robertbu.
Alternatively, why not parenting your camera to your 2D entity? Make the camera to be the child of the 2D entity if this fits. Would this work in your scenario?
The camera is static, but I'm just trying to keep the player within view, and not fall off the screen if I move to the left. I know it's the most basic thing, but any help would be great.
What about setting up invisible colliders around the stage? Use 4 boxes with box collider and disable mesh renderer.
Yea, it's what I ended up doing. Later on I'll read up on ways to do this with the camera ins$$anonymous$$d. Thanks for the suggestion though. I really appreciate it.