Game Development Reference
In-Depth Information
Towns with borders
As you saw in the preceding section, you can use Unity's camera logic to figure out where
things are on the screen. You can also do more complex ray testing to check where things
are, but I find these are overly complex unless you depend on that level of interaction.
The simpler answer is just to use the native Box2D physics system to keep things in the
scene. This might seem like overkill, but the 2D physics system is very fast and fluid, and
it is simple to use.
We already added the physics components, Rigidbody 2D (to apply physics) and a
Box Collider 2D (to detect collisions) to the player in Chapter 2 , Building a Charac-
ter . So, we can make use of these components straight away by adding some additional
collision objects to stop the player running off.
To do this and to keep things organized, we will add three empty game objects (either by
navigating to GameObject | Create Empty , or by pressing Ctrl + Shift + N ) to the scene
(one parent and two children) to manage these collision points, as shown in the following
screenshot:
I've named them WorldBounds (parent) and LeftBorder and RightBorder (children) for
reference. Next, we will position each of the child game objects to the left- and right-hand
side of the screen, as shown in the following screenshot:
Search WWH ::




Custom Search