Creating a Circular Compass

Hi all,

What I would like to do is make a compass where the needle rotates in respect to the direction that a car or airplane is traveling. I am very new to scripting and programming in general so feel free to go into detail :smile:

I have attached a picture of the type of compass I am talking about. I saw that others had done a NW—N—NE—E scrolling format and I don’t want something like that.

I will be wanting to use javascript

810300--29895--$Compass.png

I would just make the needle its own transparent image , and have it rotate on top of the other image.

This could easily be achieved by placing the needle on a plane with the right tranparency. Thats just how i would do it for simple fast implementation.

what do you mean by transparent? I am visualizing a needle you can see through (transparent)

Not at all. The compass thats under the needle, becomes a single image … the needle , is cut out of that image , and used as a lone image , with transparency , when placed on a plane over the other image , it looks just like it does now. Its really easy to set up, theres also other ways, but IMO, this is the simplest of all. Fast easy , works.

Okay I understand. So I have my player up and running and I have my Euler values printing to the screen but my question is, how do I make the needle of my compass rotate as my player rotates?

just using pseudo code here , but the idea is …either inside your player , or in side the code for the compass , create a variable referencing the others transform.

var compassPlane : Transform;

function Update(){
     compassPlane.localEulerAngles.y = transform.y;
}

okay, I will give that a shot. What are your thoughts about me making the compass needle a child of the player game object?? That way as the player rotates so will the compass needle. Or will this cause my needle to move all around the screen as my player moves?

I got it working. By the way. You are amazing!!!

Okay, how about this. I am trying to make the compass a GUI. So I need to work with textures rather than game objects. So I have gotten as far as drawing a compass to a 2D texture. Then I added a new texture which is a really thin black line (that I would use as my needle). I draw this to the screen and what appears to happen is the once thin black line is expanded to cover the whole GUI and completely covers the below compass background.

Is this what you were talking about with regards to the transparency. What I try next is make two GUIs, one that will function as the compass background and another very thin GUI that will function as the rotating needle. These two GUIs will be located directly on top of one another to give the illusion that they are one item. Am I correct in assuming this will work?

You don’t have to respond to the above post. The two GUIs have rendered nicely with the needle on top. I have to look at my code though because now my needle is rotation in a circle around the compass rather than around a single point in the middle.