Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xaxum · Nov 09, 2010 at 12:56 AM · rotationprintdegrees

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

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Herman-Tulleken · Nov 09, 2010 at 04:51 AM 0
Share

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.

avatar image xaxum · Nov 11, 2010 at 01:51 AM 0
Share

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.

avatar image Herman-Tulleken · Nov 11, 2010 at 06:23 AM 0
Share

@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.

avatar image xaxum · Nov 16, 2010 at 12:38 AM 0
Share

I posted an image to better get the idea across as well as additional text for description.

avatar image Herman-Tulleken · Nov 16, 2010 at 11:43 AM 0
Share

@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?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xaxum · Nov 11, 2010 at 03:54 AM 0
Share

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?"

avatar image xaxum · Nov 16, 2010 at 12:39 AM 0
Share

Posted further description and image.

avatar image xaxum · Nov 17, 2010 at 09:47 PM 0
Share

Responded to question above. Not sure if you get notified unless I note on your answer?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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

Transform.rotation in degrees instead of 0 to 1 2 Answers

transform.lookat axis switch during rotation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges