- Home /
2d player movement restrictions with collision boxes
Hi sorry to ask such a simple question with probably tons of answers out there but i have to hand in my diploma project in 4 hours so sadly no time for research D:
What i have is a 2d player character that moves using a rigidbody2d (using the velocity function). There are areas where the player shouldnt be able to move to (outside the screen (using a static camera that renders the entire background image), in the air, ...) i thought of using collision boxes to stop movement but i obviously forgot a step.
Please help xD
yes add an empty game objects with box collider it's simple if you have none trigger objects.
Answer by MelvMay · Apr 08, 2016 at 08:27 AM
If you want to stop the Rigidbody2D or more specifically, its colliders from moving outside the static view area then by far the cheapest way is to add a Single EdgeCollider2D component to the GameObject that has the Camera component on it then edit it so that is surrounds the screen on the left,, right and bottom and optionally the top if required.
If your player object is moving super-fast then you might want to consider setting its Rigidbody2D to use Continuous collision detection as well.
Answer by Benedikt_ · May 22, 2016 at 01:00 PM
apparently all i had to do was to add a collider to the player object -.-