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 kack93 · Jan 09, 2012 at 06:04 PM · rotationbugeuler

Weird rotation with Transform.eulerAngle

Hey guyz,

I want a sun go around my level and this is gonna be done with a constant incrementing of it's rotation.x using the Transform.Rotate function.

But I want to set the time at any moment ingame and the sun's rotation has to change, too For those who don't understand me: at 0am rotation shall be 270° so the sun shines from down to up and no light is on the terrain. At 12am the rotation shall be 90°, becouse then the sun shines from above and lights everything.

I tried this: sun.eulerAngle = new Vector3(360 * currentTime / maxTime, 0, 0); but at ~90° the sun acts completely weird!! it flips from the negative of it's current x-rotation to the positive, BUT: this bug only appears for the x-axis >_<

what am i doing wrong?

Comment
Add comment · Show 1
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 Julien-Lynge · Jan 09, 2012 at 06:09 PM 0
Share

Have you tried setting it directly to see what happens? $$anonymous$$g.

 sun.eulerAngle = new Vector3(89.9);
 sun.eulerAngle = new Vector3(90.1);

Best to simplify as much as possible. If that's acting weird, let me know, and I'll set up a blank project and see if I can reproduce your issue.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Kryptos · Jan 09, 2012 at 11:53 PM

you just encounter what is called a gimbal lock, when one axis coincides with another one (http://en.wikipedia.org/wiki/Gimbal_lock).

To avoid such a case, you should use quaternions (http://unity3d.com/support/documentation/ScriptReference/Quaternion.html)

This can be done transparently by creating quaternion using Quaternion.LookRotation() or directly changing a gameObject's rotation with transform.LookAt().

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 Bunny83 · Jan 10, 2012 at 03:59 AM 0
Share

Well, Unity always uses quaterions to represent a rotation. That's actually where this problem comes from. It's the conversion between a quaternion and eulerangles. Reading back the eulerangles after assigning a gimbal-lock combination will result in eulerangles which represents the same rotation, but with different values. That's why the documentation says you shouldn't increment(read / change / write) the eulerangles.

It's better to set them to absolute values that don't rely on the previous ones. Usually you would use localEulerAngles which is equal to eulerAngles for GameObjects without a parent. Childobjects are affected in localspace so you can use a parent to setup the rotation axis and use the childs localRotation / localEulerAngles to rotate the child.

I think LookAt or LookRotation are the most inappropriate functions for this task. AngleAxis will create a rotation around a specific axis but if the rotation should be around a local axis (x,y or z) it's easier to just use Quaternion.Euler or like already mentioned eulerAngles / localEulerAngles which uses Quaternion.Euler internally.

avatar image
1

Answer by kack93 · Jan 09, 2012 at 11:14 PM

facepalm

The point is that i CANNOT do this (what I actually did)

 sun.eulerAngle = new Vector3(360 * (currentTime / maxTime), sun.eulerAngle.y, sun.eulerAngle.z);

BUT

 sun.eulerAngle = new Vector3(360 * (currentTime / maxTime), 0, 0);

which I cannot understand, but anyways I got it now...

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 Tseng · Jan 10, 2012 at 02:36 AM 0
Share

That's because your rotation is absolute and you only change x. This won't work in cases where y and z aren't "hardcoded"

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

How can I multiply the rotation of a mirrored object? 1 Answer

Character Controller strange collision bug 2 Answers

Pitch/yaw difference between 2 transforms 1 Answer

How do you manually override mecanim's interpolation with rotations? 2 Answers

Rotate an object around z axis on user input 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