Early Game Puzzle - Finding the Terrorist

One of the story portions involves the player finding a Terrorist who has performed a recent bombing.
To do this I came up with a simple puzzle: Have the player look about at a map of the world and locate the Terrorist as they example the map.

The idea is that whilst examining the map, a cross-hair will appear and as they get closer to the location of the terrorist, a sound will play (with increasing speed) and a faint glow will increase as they encroach. To do this we use Raycasting, which sends out a invisible line between the player and the world surrounding them.

We use a Prefab to create the cross-hair object only when the Raycast hits a object on a specific layer.


The code then compares the distance between the cross-hair prefab and an invisible object attached to the map. If its lower than a certain value, then it creates a second prefab, that of a glowing object.


This prefab has its own script which increases the alpha of the colour rendered as it gets closer.

There was initially a bug in which for a single frame it displayed the default alpha transparency and the wrong colour. This was solved by setting the initial scale of the prefab to 0 and resizing it at run-time.




The code seemed to work - up until I actually imported it into the main project. It turned out the raycast was not producing the crosshair at the middle of the screen like it should've done, and was fairly offset from the center. This will require further investigation into fixing it.

Further improvement to the code will be done by removing the "magic numbers" and assigning named constants at code start to store numbers so the code is more readable and easier to edit. But for now I will need to get the puzzle working.

A video of the working puzzle can be found in a later post.

Popular posts from this blog

Puzzle 2 - First Attempt

102CR Portfolio