- Home /
Print out degrees around an object
I have a game object at 35,0,0. I want to have the degrees printed to the screen around the object every 15 degrees. So people know where they are when they turn around the object. What is the best way to print this text at a fixed distance from the circle so they can always see how far they have rotated from 0? I know I can do graphics for the numbers and load them in the appropriate place but I would like to be able to use a GUI or something to do this automatically that way I can easily change color or size or location.
I am looking to put compass marks around the player camera so they can see which direction they are pointing at all times. I am attaching a rough sketch. I would like to just make 1 major tick and 1 minor tick and place these around the player with a script so I can change the distance around the player easily plus the compass needs to always be around the player wherever they go and stay in the same orientation. Not sure how to do this. Image
I am not sure whether you want to draw in the scene in 3D space, (perhaps on some plane), or on the GUI. In my answer below, I assumed the latter - if this is not what you meant, please clarify.
Herman sorry for not being clear. New to unity so I don't know the advantages to either way. What I care about is having the degrees visible so the player can see what orientation they are facing as they turn the camera. I am not familiar with what different items the GUI system is capable of. I would like to print the numbers ins$$anonymous$$d of doing graphics for all of them is the other key element.
@xanum $$anonymous$$aybe draw some pictures of what you want? I am afraid I still not quite understand what you want ;) Perhaps a picture of the player facing north and south, and how you would like the degrees displayed in each case.
I posted an image to better get the idea across as well as additional text for description.
@xaxum I am a bit slow... Is this what you want: The player is in the scene, facing north. The camera is 3rd or 1st person, not top-down. Around the player is a compass, with North facing upwards. Now the player turns to the South. As the player moves, the compass rotates, so that when the player faces South, South on the compass is at the top? You said you could not solve the problem in the GUI: is this because of a technical reason, or because you want the compass physically in 3D space?
Answer by Herman-Tulleken · Nov 09, 2010 at 04:50 AM
(This is for a GUI compass)
The easiest way would be to make a texture with the compass on it, and then use this:
http://unity3d.com/support/documentation/ScriptReference/GUIUtility.RotateAroundPivot.html
to rotate it.
If I recall correctly, [and someone please correct me if I am wrong], the thing rotates everything in the OnGUI function after being called. So in certain scenarios, you might need to do something like this:
public void OnGUI()
{
//do stuff
//rotate y degrees
//draw compass
//rotate back (i.e, rotate -y degrees)
//do other stuff
}
The value y here is easily calculated from the Euler angles of the object (the player) - it is simply player.transform.rotation.eulerAngles.y
.
To keep text upright, you need to draw it over the rotated texture at the correct screen coordinates. The following should draw a label every 30 degrees:
public void OnGUI() { //do stuff //rotate y degrees //draw compass texture //rotate back (i.e, rotate -y degrees)
//draw text for(int i = 0; i < 12; i++) { string label_text = (((i 360) / 12)).ToString(); //in degrees float angle = i / 12.0f 2 Mathf.PI; //in radians int x = radius Mathf.Cos(angle); int y = radius * Mathf.Sin(angle);
GUI.Label(new Rect(compass_center_x + x, compass_center_y, y, label_width, label_height), label_text);
} }
Here, radius
is how far you want the text to be displaced from the center, label_width
and label_height
are the dimensions of the label (that of course depend on the font). compass_center_x
and compass_center_y
are the screen coordinated of the compass. You will have to use a GUIStyle
to anchor the text in the center.
Upon further experimentation I don't know I can do this with a GUI. A GUI. I need the compass to be stationary as the camera turns. If I specify the label coordinates they are a fixed space in relation to the camera not the world. So when I turn 0 degrees is always in front of me. I am not sure how to get the texture to stay fixed in the world with a gui. I guess my question now should be "How do you place a game object around a point at a fixed distance and repeat it X degrees and associate a text label to those game objects using a script to take one model and replicate it around?"
Responded to question above. Not sure if you get notified unless I note on your answer?
Your answer
![](https://koobas.hobune.stream/wayback/20220613082409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i get Y rotation of Transform in degree ?? 1 Answer
Snap the rotation 0 Answers
Rotating A Character 180 Degress 1 Answer