Forum rules - please read before posting.

Implementing a compass

Hey all - 

I'm thinking about adding a compass inventory item.  Something similar to the one in Quest for Glory II that when you use it from your inventory a little graphic would show up on screen and have the arrow pointing whichever direction north is (I'm thinking it would get that info based off of whatever X/Z position the current camera is set to).

Any thoughts of how to execute something like this?


  • Rather based on the current camera's rotation, I should think?
  • Unless of course you've got the actual north pole inside or very close to the playable area, in which case the X/Z position must be taken into account as well ... :-)
  • Just threw this together - something along those lines?

  • @snebjorn - Yes!! That looks great!  

    And yes, I meant rotation.  Not enough caffeine, yet.  :D

  • edited September 2015
    I know the feeling ...  :-)

    Anyway, here's the code: 


    using UnityEngine;
    using System.Collections;

    public class Compass : MonoBehaviour {

        public Texture compassTexture;
        public float screenPositionX = 50;
        public float screenPositionY = 50;

        void OnGUI()
            Vector2 compass_center = new Vector2(screenPositionX + compassTexture.width / 2, screenPositionY + compassTexture.height / 2);
            GUIUtility.RotateAroundPivot(-(transform.eulerAngles.y), compass_center);
            Rect compass_rect = new Rect(screenPositionX, screenPositionY, compassTexture.width, compassTexture.height);
            GUI.DrawTexture(compass_rect, compassTexture);


    Put it in a script named Compass.cs, add that to you main camera, set the texture to taste (preferably a square image that rotates around the exact centre in an aesthetically pleasing way, and was imported as a sprite) and you're good to go.

    Depending on how you want this to appear in-game, there might a bit more work to do ... but here's a starting point.
  • This is great, thanks @Snebjorn!  I'll give this a shot!
  • @Snebjorn - Okay!  Got it in and working with new art.  Hooray!  Now I just need to figure out how to turn it on/off based on an inventory interaction.  I did a quick test where I created a child object to the main camera with the Compass.cs (so it would retain the camera's rotation data) and did a simple test to turn on/off the visibility when "using" the compass in my inventory but that didn't work.

    I'll need to spend more time investigating!
  • This script is obviously very much a "quick'n'dirty" solution to the immediate problem of getting a compass working. A more solid version should probably have the compass as a separate object that integrates directly with AC.

    The stuff I'm working on at the moment includes a large outdoor scene where you can easily get lost, so why not give the player a compass to pick up? I even find myself losing my bearings sometimes, and I designed the damned thing!

    There's a nice little side project: a compass that works with AC ... watch this space! :-)

  • edited September 2015
    Ooooooh!  This is very exciting!  Thanks @Snebjorn!! :D
  • You came up with the original idea, so let's share the profits from the asset store - just keep your red Ferrari off my parking space, ok? :-)
  • FerrariS.  Plural.  My god, we're going to be rich.
  • edited September 2015
    But we'll still remember where we came from! :-)

    Anyway, in order to not pollude this part of the forum with this, I've created this thread:

    ... let's continue the discussion there.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!