Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jahames · Jan 24, 2017 at 04:33 PM · scripting problemangles

How do I convert an angle from Unity to an angle on the (mathematics) Unit Circle?

In Unity the angle at 0 degrees is pointing up and to rotate this angle 360 degrees we rotate it clock wise.

This is quite different from the unit circle used in mathematics. The unit circle has 0 degrees pointing right and to rotate it 360 degrees we rotate it counter clock wise.

Ultimately what I want to do is to create a unit vector from the rotation of a GameObject's forward direction.

Comment
Add comment · Show 2
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 HenryStrattonFW · Jan 24, 2017 at 08:29 PM 0
Share

If you wanted a unit vector of the transforms forward direction, could you not just use transform.forward?

EDIT: actually never tested if this transform.forward is normalised in worldspace or not, I have always assumed so, but if you you could always just normalise if just in case.

avatar image streeetwalker HenryStrattonFW · Sep 23, 2020 at 03:12 PM 0
Share

all of the transform direction vectors are normalized and in world space.

1 Reply

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

Answer by jahames · Jan 26, 2017 at 01:02 AM

After an hour of scratch work and testing I came up with a solution that I think sovles my problem.

     // new algo
     angle += 90;
     angle -= angle * 2 + 180;

     // convert degrees to radians
     angle *= Mathf.PI / 180;
     float deltaX = Mathf.Cos (angle) * magnitude;
     float deltaZ = Mathf.Sin (angle) * magnitude;
     vector3 = new Vector3 (deltaX, 0f, deltaZ);

Note that the angle is gameObject.transform.rotation.eulerAngles.y in my code.

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 Demigiant · Sep 23, 2020 at 11:04 AM 0
Share

Perfect, thank you.

avatar image Bunny83 Demigiant · Sep 23, 2020 at 09:14 PM 0
Share

You don't really use this code as it is, do you? -.-

Those two lines

  angle += 90;
  angle -= angle * 2 + 180;

are just

 angle = 90 - angle;


Instead of

 angle *= $$anonymous$$athf.PI / 180;

it's usually better to use

 angle *= $$anonymous$$athf.Deg2Rad;

as it's more descriptive.

avatar image Demigiant Bunny83 · Sep 23, 2020 at 10:18 PM 0
Share

To be precise,

 angle *= $$anonymous$$athf.Deg2Rad;

is also faster other than more descriptive :P

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

8 People are following this question.

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

Related Questions

3D text deformed while rotating 0 Answers

why Crossplatform input Joystick behaving weirdly with FirstPersonController from Standard Assets? 0 Answers

trying to add a gradiant to text: Assets/ArcadeScripts/GradiantTextEffect.cs(18,30): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 1 Answer

When I apply the script, I get an error message. 0 Answers

Grading system not working 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