I am developing a game with Unity 2017.
The game mechanics are as follow:
- Classic top-down RPG;
- Movements are: UP, DOWN, LEFT and RIGHT;
- Player evolves in a 16*16 map;
- He can dig in the direction he wants to make his way through the map one tile at a time;
At first I was using a very classical approach using tilemaps, RigidBody2D and BoxCollider2D on tiles and the player GameObjects.
Collision detections went fine and my tilemap looked pretty much like that (red being the walls and white the empty spaces):
The problem with this approach is that I have to keep in memory the state of 256 tiles in a
List<Vector2f> and to create the 256 expected GameObjects representing either my walls (which a totally black), or my floor (the empty space).
Creating a black GameObject with its own BoxCollider2D for each of the tile seems a little bit overkill. And this brings me to the second iteration of my game: to keep in memory only the tiles the player digged.
What I would like to achieve efficiently, is to let the player evolve as long as he is colliding with an underlying tile, but stop moving as soon as he doesn’t.
This is ok:
This isn’t, and player should be placed to previous state.
I could take advantage of
OnTriggerEnter2d and handle custom collision and response, but I have the feeling that something more simple and more optimized may exists somehwhere in the wild!
Thanks to any help provided!