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
1
Question by BramG · Feb 15, 2012 at 09:59 PM · c#rotationeuleranglescircle

Odd discrepancy with EulerAngles (Circular motion, C#)

I'm working on creating a circular motion while the object itself rotates to follow the circular path it is on. While the motion isn't much of a problem, the rotation seems to be slightly off and I can't figure out why.

I use the code below to move the object, as well as rotate it. While it seems to be -almost- fine, the rotation always seems to be off just a bit. I've traced a few things and found out the following: When I set the angle to zero, by my code the rotation of the object should be 360 degrees when I run the script. When I trace the yRotation variable it reflects this nicely. However, when I look at the actual rotation in the editor it gives me a rotation on the y-axis of 106.

I try not to use Rotate.LookAt, Transform.RotateAround or anything of the sort.

Does anyone know why this is?

 void Update () {
 angle += Input.GetAxis("Horizontal")*10*Time.deltaTime;
     
 Vector3 newPosition = transform.position;
 
 newPosition.x = Center.x + radius*Mathf.Cos(angle);
 
 newPosition.z= Center.z + radius*Mathf.Sin(angle);    
 
 float yRotation = 360 - angle;
 print(yRotation);
 
 transform.rotation = Quaternion.EulerAngles(0,yRotation,0);
     
     
 transform.position = newPosition;
 
 }
Comment
Add comment
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

1 Reply

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

Answer by aldonaletto · Feb 15, 2012 at 10:57 PM

You're mixing degrees and radians: Mathf.Sin, Mathf.Cos and Quaternion.EulerAngles are functions that receive arguments in radians, not degrees.
If you want to keep things in radians, define only the starting angle in degrees and convert it to radians:

public float startAngle = 0; // starting angle in degrees

void Update(){ ... float yRotation = startAngle * Mathf.Deg2Rad - angle; transform.rotation = Quaternion.EulerAngles(0,yRotation,0); transform.position = newPosition; } NOTE: Quaternion.EulerAngles(...) is a deprecated function that receives angles expressed in radians (it's not even listed in the docs). For angles in degrees, use Quaternion.Euler(...) instead.

Comment
Add comment · Show 1 · 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 BramG · Feb 16, 2012 at 08:37 AM 0
Share

Works like a charm, thank you!

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

6 People are following this question.

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

Related Questions

Flip over an object (smooth transition) 3 Answers

RotateAround reversing doesn't work with negative vector3 0 Answers

Multiple Cars not working 1 Answer

Camera rotation behaving strangely 2 Answers

How to set a single-axis rotation and not change the others axes 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