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 fajoaq · Mar 21, 2013 at 09:33 PM · angleitweenmathfradiusmoveto

Mathf to get point on edge of circle (via radius and angle)

Hi guys, I am trying to create a GUI wheel with power-ups icons and having some trouble. I researched this quite a bit, and what I want it to do is put one gui element an equidistant space from the center of a circle area (thus creating a "power wheel"). However they are appearing unevenly spaced. I checked with some Debugs and it seems like the 360 degree circle is being split evenly according to the number of elements. Can you guys take a look at the code and point probable cause out? Thanks!

 Debug.Log(angle);
         rad = Screen.height * .00017f;
         for(int i = 0; i < powerL.Length; i++){
                 //Debug.Log(angle);
                   tweenObject[i] = (GameObject)Instantiate(Resources.Load("3dText"));
                     tweenObject[i].transform.name = powerL[i];
                 tweenObject[i].transform.parent = spawnPoint.transform;
                 tweenObject[i].transform.position = new Vector3(.15f,.4f,.01f);
                     float X = tweenObject[i].transform.position.x + rad * Mathf.Cos(angle);
                         float Y = tweenObject[i].transform.position.y + rad * Mathf.Sin(angle);
             
                             Vector3 finalPos = new Vector3(X,Y, 0);
             //Vector2 finalPos = new Vector3(X,Y, 16.2785f);
             
         iTween.MoveTo(tweenObject[i].gameObject,finalPos, .5f);
         angle = angle + (360 / powerL.Length);
             Debug.Log(angle);
         }
Comment
Add comment · Show 3
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 Benproductions1 · Mar 21, 2013 at 09:49 PM 0
Share

if you did this with GUI elements, it would be so much easier :P

avatar image Benproductions1 · Mar 21, 2013 at 09:50 PM 1
Share

also cos and sin take an angle in radians, not degrees

avatar image Owen-Reynolds · Mar 22, 2013 at 02:45 PM 0
Share

GUITextures can be simpler in that they are already in camera space -- you don't have to keep them in front of a moving camera.

But, if the power-ups will be rotating 3D models, can keep them as 3D transforms and use a second camera (adjusting layers and viewport.) The text can then be 3DText objects.

1 Reply

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

Answer by Owen-Reynolds · Mar 21, 2013 at 10:11 PM

As BenPod comments, Cos and Sin expect radians. 6.28 radians is 360 degrees. So if you use 45 "degrees", the computer spins 7 full circles and looks at the remainder, which is essentially random (which way is 12,060 degrees? After subtracting all the 360's, could be anything.)

To fix, use Mathf.Cos(angle* Mathf.Deg2Rad );. Deg2Rad is just 6.28/360, about 57.

Comment
Add comment · Show 2 · 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 Bunny83 · Mar 21, 2013 at 10:38 PM 0
Share

It's actually about 0.0174 ;) 57 is the multiplicative inverse. That's the value of Rad2Deg. Anyways, correct answer ;)

avatar image fajoaq · Mar 22, 2013 at 12:53 AM 0
Share

Thanks guys. I appreciate the help. I will look into GUI elements again. (I believe I tried it at one point)

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Checking Attack Radius, or "Width" 1 Answer

iTween movetopath 1 Answer

Go back to first node (itween + moveto) 2 Answers

itween moveto not working 1 Answer

Moving a cylinder connecting two spheres 0 Answers


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