Escape room devlog 7: Spawning Randomised Actors

This week I created a ccontrolled randomised spawning script for the starting and end pieces.

Firstly I created an array of all the tiles manually so I could garuntee they were in numerical order

For the first peice I simply generated a random number from 0-23 and used that number to take the location of a tile that has that index.

However I wanted it to also spawn in a random direction so I had to create a function that stopped it from being able to face the outer bounds and create a unsolveable puzzle.

The function took the index of tile, and checked for each outer location, then set the possible rotations to ones that would not face the outer bounds. There may have been more optimal ways to do this however I like to do things manually and accurately to minimise mistakes.

To spawn the next peice it is a little more complicated as it has to check for the previous peice and all the tiles in a 1 tile radius.

I created this function to check from an array of tiles then calculate the grid of tiles from the first selected tile and remove them from the possible spawn indexs.

I wrote it like this so I could reuse the code for the third tile and just change the arrays to the second ones instead of the first.

This is the 3rd peice being spawned. You can see the inputs to the previous 2 variables being set then the using them to spawn the peice correctly.

Their is one flaw with this code which is present with all peices including the placeable oness is that the spawn rotation and location only works in that one axis, as Im changing the world directions not the local directions, I looked into how to fix it much as I have higher priorities but I will make a blog on it at in the future.

Next blog I will probably work on the power being able to flow through the wires from the start to the 2 ends then set a variable when its open which I in further future will use to close/ Open doors.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *