English
In this
post I'm going to explain how we are going to manage the collision detection in
Unity. Even being a 2D game, I decided to use the 3D tools that Unity offers.
The map is composed by tiles, and in the map editor I choose which ones will be
an obstacle and which not. For those which are obstacles I instantiate a Box
with a Box Collider attached to it. Then, I attach a Character Controller to
the player, which manages the collisions with all the Colliders in the scene.
Via scripting I choose how to move that Character Controler so, internally, it
checks for collisions and allow or not the movements. Video below.
Spanish
En este
post voy a explicar como vamos a controlar la detección de colisiones en Unity.
Aun siendo un juego en 2D, he decidido usar las herramientas 3D que ofrece
Unity. Cada mapa está compuesto por una serie de tiles o cuadraditos, y en el
editor de mapas elijo cuales de ellos van a ser un obstáculo y cuales no. Para
aquellos que son obstáculos instancio un Box con un Box Collider. Luego, le
asigno un Character Controller al jugador, que gestiona las colisiones con
todos los Colliders de la escena. A través de scripting decido como mover este
Character Controller e, internamente, mira si hay colisiones y permite o no el
movimiento.
Obviously, In the end these white blocks won't be shown :)
Obviamente, los cuadrados blancos no se verán en el juego :)