FYP - Trials of Chaos: Grid Manager
Introduction
Hi, Welcome back to my blog, my name is Joshua Mootoo and in todays blog post i will be going over the struggles and triumph when creating the Grid Manager for Trials of Chaos.
What i had to start off with
In the last post I had created a partially working Grid Manager where it would Instantiate the Initial Grid, detect what level tile the player was on through collision detection and make that the centre tile, when the player would move onto another tile, it would delete any tile that wasn’t surrounding the new centre tile.
My Struggles With The Grid Manager
The main problem I had was with generating/Instantiating the missing tiles after the player had moved onto a new tile, as I had no way of getting the correct location of the missing tiles. I also had a weird player collision as the player moved across to another tile as each tile had a separate Mesh Collider.
My First attempt at fixing the issue
The way I initially instantiated the tiles was using pre positioned empty game objects, using their positions for where the tiles were instantiated. i first tried moving that grid of empty game objects to instantiate the new tiles but i still didn’t have a way for making sure i instantiated the new tiles in the correct place.
Final Solution
for my solution for this problem i ended up rewriting the whole script. the grid is represented by a 2 dimensional array of Game Objects, the size determined by the ‘gridSize‘ variable which is set to 3.
as the player moves the grids position and the center tile is tracked based on the players position instead of the collision between the tile and the player, the script would then dynamically load / unload the level tiles based on a load distance from the center tile which is set to 1.
Each time the tile is loaded in its randomly selected from the ‘tileTipes’ array of tile prefabs, the tiles rotation is also randomly selected from the ‘possibleRotations’ float array.