Transitioning and bounds
So our camera follows our player, but our hero can still walk off the screen and keep going forever, so let us stop that from happening.
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, Character Building. 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...