- Home /
I can't create a world border?
So i've almost completed my game. It is a 2D gamje where the character moves across this world trying to avoid the enemies. When I go up, the character never stops. Is there a way to create a simple world border around my world? Meaning, that the character stops at some point and doesn't continue to leave the map.
This problem is typically solved by clamping the position of the character so that he cannot travel beyond a certain range. Less frequently it is handled by colliders around the edges of the map. A specific answer requires more information: how you are moving the character, your movement code would be helpful, verification that your map is on the XY plane, verification that your map is centered on the XY origin.
Answer by Gruffy · Mar 08, 2014 at 11:01 PM
if your world is effectively a square then line up, at each side, an empty gameobject with a box collider. if your player has a rigidbody or collider attached to it also, when you reach these box colliders at the edge of your world, they should stop you moving past the world edge. For surety, align each GameObject with it`s repsective BoxCollider (stretched out to cover the length of your world`s sides) and bring them into your world edge a little to ensure the collision happens before you actually fall of the world. ![alt text][1]
Overall, to give you a more succinct answer we would need to know how your player is being handled (Rigidbody or simple input triggered translation and rotation) You may find these links below helpful aswell. [Unity Student (in JS im afraid but that should be too scary)][2] And of course, the best place to start... [Unity Script ref: Collisions][3]
Take care and Thanks for reading. Gruffy [1]: /storage/temp/23323-diagram.png [2]: http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/ [3]: http://docs.unity3d.com/Documentation/ScriptReference/Collision.html