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 imarriedyoung · Oct 09, 2013 at 03:43 AM · rotate objectquaternions

Quaternions, Eulers, and Small Float Values?

I have this itty bit of code…

 using UnityEngine;
 using System.Collections;
 
 public class PlanetManager : MonoBehaviour {
 
     void FixedUpdate()
     {
         rotateSun();
     }
     
     float degreesRotation;
     
     //rotate sun
     void rotateSun()
     {
         //Y degrees the ratio between every angle to every second in a day
         degreesRotation = 360.0f / ( Time.deltaTime * GameTime.speedOfDay * 86400.0f ); //0.004166667
         
         //rotate the sun by Y degrees for every second that passes
         print (degreesRotation);
         Quaternion rotation = Quaternion.AngleAxis( degreesRotation, Vector3.right ); 
         transform.rotation *= rotation;
 
 //        transform.Rotate(Vector3.right * degreesRotation);
         
 //        print(transform.rotation);
 //        print(rotation);
 
     }
 }

My issue lays in the fact that what degreesRotation spits out seems too small a value for any effect on the rotation - the object stays at it's same angle and doesn't move. If I test with a magic number like 0.05f it works, but if I add one more decimal point like 0.005f I seem to get nothing again. I've tested this with a few alternatives, as you can see, some in Quaternion (like Quaternion.Euler) since gimbal lock is a fear, and some with transform.Rotate / adding new vectors bit by bit.

Is my math wrong? or is this simply a 'thing' with these functions?

Comment
Add comment · Show 14
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 robertbu · Oct 09, 2013 at 04:36 AM 0
Share

I cannot create a simple reproduction of your issue. Are you sure that the rotations you are entering are big enough to have a visual effect frame to frame? I thought there my be some sort of rounding going on, so I tried this bit of code:

 #pragma strict
 
 private var rot = 0.000005;
 
 function Update() {
     for (var i = 0; i < 10000; i++) {
         //transform.Rotate(0.0, rot, 0.0);
         transform.rotation = Quaternion.AngleAxis( rot, Vector3.up) * transform.rotation; 
         }
 }

It applies a very small rotation 10,000 times per frame. I tried with both both the comment out line as well as the AngleAxis() line. Both worked fine. Pushing to 100,000 iterations with a 1/10 smaller value had the frame rate dramatically dropping, but the object did continue to rotate. So entering small values in the routines does not appear to be your issue.

avatar image robertbu · Oct 09, 2013 at 04:48 AM 0
Share

Took a second look. I don't know the value of GameTime.speedOfDay, nor do I know what 86400 represents, but if the whole line sets 'degreesRotation' to 0.0042 as suggested by the comment, then the object will rotate a about a degree every four seconds (when running on average at 60 FPS). So I tried it with:

 #pragma strict
 
 private var rot = 0.004;
 
 function Update() {
         transform.rotation = Quaternion.AngleAxis( rot, Vector3.up) * transform.rotation; 
 }

And I got an about one degree every four seconds rotation.

avatar image imarriedyoung · Oct 09, 2013 at 01:08 PM 0
Share

Tried that, changed Vector3.up to Vector3.right (so X axis ins$$anonymous$$d of Y) and it still won't move, however if I have it with your setup, on the Y axis, it will. The current light this is applied to is at -90 degrees on the X axis. If I change it to zero, for example, it does work, so it sounds like gimbal lock, but with a Quaternion?

Also, that would mean my math is definitely wrong. I'm trying to get this light to move N amount of angles per 1 second and smoothed out accordingly (via Time.deltaTime). Of course, to GameTime one second is not a constant 1 but ins$$anonymous$$d a the result of this expression

 seconds += speedOfDay * Time.deltaTime;

With a clause to reset after it has been 86400 seconds, or 1 day. The system works great, and it pairs up exactly with a stopwatch outside of the system, but that leaves me with trying to figure how how to make the sun move in accordance to time. Any ideas? Thanks for your time and words.

avatar image robertbu · Oct 09, 2013 at 02:36 PM 0
Share

Is this just a local vs. world axis issue? What happens if you use transform.Rotate() ins$$anonymous$$d of Quaternion.AngleAxis()?

avatar image ArkaneX · Oct 09, 2013 at 03:17 PM 0
Share

@imarriedyoung - why do you use FixedUpdate and not Update?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

16 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 avatar image avatar image avatar image

Related Questions

Quaternion reset rotations didnt smooth 0 Answers

Object doesn't rotate properly 1 Answer

Rotating an object in relation to its endpoints 1 Answer

How to steer a vehicle 1 Answer

How can I make a character look in a direction that's halfway between its direction of 2D movement and facing the camera? 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