Lost at sea, not on my watch!

We decided as a team, halfway through the development, that some kind of direction indicator was necessary to add to the game. Since we re-designed the gameplay of the game and used a more open world we had to make sure that the players would be able to complete their tasks. It was decided that a compass, pointing to the current objective, should be implemented.

My goal with the compass was to make sure that it directed the player towards their current objective, but also that it would be reusable if need be. I decided to code the compass in such a way that it pointed towards game objects in the world of the scene. I choose this approach since that would mean that I could make the compass point towards what ever I wanted it to, as long as a game object was present in that area.

Image: Beautiful MS Paint demonstration

Compass demo

Red line – Undesired, Green line – Desired

Since I wanted the compass to take care of itself, it was important to remember that the compass’ location could not be used as a point of reference. The desired outcome was that the compass would reference the player’s position when calculating how much to rotate the pin, and not its own. The reason I considered this the desired outcome was because it would provide more accurate feedback to the player.

 

Image: Script in Unity inspector

Rotate pin

The end result of the compass ended up being exactly what I wanted it to be from a functionality and use standpoint. To make the compass as re-usable as possible, I decided to turn the points of interest into Serialized fields of private Transforms so that it would be as conveniant as possible to add new objectives while still making sure that no other scripts could alter the points of interest. The transforms were then stored within an array that was used by the function determining the current objective. The Compass Carrier is the object used as the main reference point for the compass. The carrier is the ship in this case, but it could be whatever you want it to be.

 

While the compass worked just the way I wanted it to, there are still some things that can be improved if enough time is available. As of right now, the compass points towards the points of interest in a set order. This could be changed into a functionality where the compass determines which one of the points of interest that are closest to the player and point to that specific object.

 

/Jesper H. Backman

 

Leave a comment