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 PsychoHead · Mar 18, 2013 at 05:35 PM · rotationitweenoffset

Weird offsets by iTween?

Hey guys, I hope this is less of a mystery in the end, then it is to me.

Basically what I have is a Player, which gets rotated around his local x axis by a mouse script.

A second script rotates the player around the global axes, always 90 degree. Now here is the problem: using transform.Rotate(eulerAngles, Space.World), I only get an incredibly small, unproblematic offset, so that the player gets almost perfectly aligned to the global axes in the end.

However, when I use itweens iTween.RotateAdd(), also in global space, I get a significantly bigger offset. This offset adds on, until the Player isn't aligned anymore, practically not orthogonal anymore.

Errors that I have tested/disproved:

  • It's not caused by some sort of gravity or selfmade force. I've turned it off and made the attached rigidbody of the character kinematic.

  • It's not caused by mouse look. Even when not using mouse look, an offset occurs.

  • It always gets passed 90 degree-rotations

Is there any known issue that could cause this kind of behaviour, or do you need some script and/or pictures?

EDIT: Here's the code, also posted in comments

 public void switchGround()
     {
         //Some code to determine the normals which is pointed at with raycasting
 
     Quaternion desRot = Quaternion.FromToRotation(transform.up, hit.normal);
         float desRotX;
         float desRotY;
         float desRotZ;
 
         //normalizing it to 180 degree max
         if (desRot.eulerAngles.x > 180) { desRotX = desRot.eulerAngles.x - 360; }
         else { desRotX = desRot.eulerAngles.x; }
         if (desRot.eulerAngles.y > 180) { desRotY = desRot.eulerAngles.y - 360; }
         else { desRotY = desRot.eulerAngles.y; }
         if (desRot.eulerAngles.z > 180) { desRotZ = desRot.eulerAngles.z - 360; }
         else { desRotZ = desRot.eulerAngles.z; }
 
     Vector3 ea = new Vector3(desRotX, desRotY, desRotZ);
 
     if (ea.magnitude < 178)   //I want to handle 180 degree rotations manually
         {
             if (!rotating)
             {
         //clamping it to 90 degree rotations
                 if (Mathf.Ceil(desRotX) >= 45) desRotX = 90;
                 else if (Mathf.Floor(desRotX) <= -45) desRotX = -90;
                 else desRotX = 0;
 
                 if (Mathf.Ceil(desRotY) >= 45) desRotY = 90;
                 else if (Mathf.Floor(desRotY) <= -45) desRotY = -90;
                 else desRotY = 0;
 
                 if (Mathf.Ceil(desRotZ) >= 45) desRotZ = 90;
                 else if (Mathf.Floor(desRotZ) <= -45) {desRotZ = -90; }
                 else desRotZ = 0;
                 
 
 
                 ea = new Vector3(desRotX, desRotY, desRotZ);
 
                 //transform.Rotate(ea, Space.World);    <---- This works fine
                 iTween.RotateAdd(gameObject, iTween.Hash("amount", ea, "time", 0.4f, "space", Space.World, "onstart", "rotStart", "oncomplete", "rotComplete", "easetype", "easeInOutCubic"));
         //This doesn't. onstart and oncomplete functions get called to make the rigidbody kinematic and stop gravity for the rotation
             }
         }
         else
         {
         //What happens for 180 degree rotations, not important for the question
         }
 }
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 robertbu · Mar 18, 2013 at 05:36 PM 0
Share

It is easiest for folks on the list to figure out these kinds of problems if we see the code.

avatar image PsychoHead · Mar 18, 2013 at 05:39 PM 0
Share

Okay, I hoped I could get away without posting it, since it's a rather long bit of code. Let me see if I can condense it down to the essential parts, then.

avatar image PsychoHead · Mar 18, 2013 at 06:00 PM 0
Share
  • code edited in the first post -

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Mar 19, 2013 at 12:00 AM

Transform.Rotate() here is going to happen between one frame and the next. iTween.RotateAdd() will happen over time, and at each frame some of the total rotation is added to the current rotation at that time. So you get a sort-of compounding with iTween.

Local and global may not mean what you think they mean. Typically when I have two different kinds of rotation like you say you have, I isolate one rotation from the other by using an empty game object. So the empty parent game object get the "global" rotation, and the child character get the "local" rotation. This doesn't solve every kind of rotation, but it can solve a lot of headaches when it does.

Also you are reading back the euler angles from the rotation. Without going through your logic in detail (I see you are attempting to normalize everything), I cannot say that what you are doing won't work, but typically it is a bad idea to read euler angles. There are multiple euler angles for any specific rotation, and the euler angles readings from Transforms or Quaternions often don't give back what you would expect. One moment you might have a rotation of (179.9,0,0) and the next it will return (0,180,180) for example. When I need to do this kind of thing, I treat euler angles as 'write-only'. I maintain my own Vector3 and assign it to Transform.eulerAngles or Transform.localEulerAngles each frame.

Comment
Add comment · Show 4 · 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 PsychoHead · Mar 19, 2013 at 10:17 AM 0
Share

I see what you are saying there. I did as you recommended, but it didn't help. Separating the rotations gives the same result. Not reading eulerAngles doesn't seem to help either - that being said, I need to read them at least once.

So, I get the following scenario: I make two rotations, each 90 degree. The following lines show the vectors of the rotations. The first one is the one generated by FromToRotation, the "NOR$$anonymous$$:" one is the one that gets used in the iTween Rotation.

Rotation 1: (270.0, 0.0, 0.0) NOR$$anonymous$$: (-90.0, 0.0, 0.0)

Rotation 2: (270.0, 0.0, 0.0) NOR$$anonymous$$: (-90.0, 0.0, 0.0) The Player-Transform shows an offset of 3 degree in x-direction in the editor here, which is also easily noticeable.

avatar image PsychoHead · Mar 19, 2013 at 10:38 AM 0
Share

Okay, I'll just use Quaternion.Slerp again, if we can't find a solution. I switched to iTween in the first place, since I didn't want to separate Rotations as you mentioned, and it seemed generally easier.

Still though, it would be nice to know what causes this issue.

avatar image robertbu · Mar 19, 2013 at 04:29 PM 0
Share

I too don't like when I don't understand something. If I can play a bit I can usually figure out what is going on. Do you have a simple piece of code that demonstrates the problem? It just has to do the two rotations you mention. If so perhaps I can figure it out.

avatar image PsychoHead · Mar 19, 2013 at 05:03 PM 0
Share

I got my functionality using regular Slerps by the way, not using iTween for precision rotation anymore.

When I just put together the following example for you, I noticed that the attached rigidbody seems to cause the problem. So: you can reconstruct the problem, if you just attach something similar to this script to an object with a rigidbody:

     void Update () {
         if (Input.GetButtonDown("Fire1"))
             iTween.RotateAdd(gameObject, iTween.Hash("amount", new Vector3(-90, 0, 0) , "time", 0.4f, "space", Space.World, "oncomplete", "rotComplete", "easetype", "easeInOutCubic"));
     }
 
     void rotComplete()
     {
         Debug.Log(transform.eulerAngles);
     }

$$anonymous$$aking the rigidbody kinematic or setting angular drag to zero isn't the solution.

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

10 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

Related Questions

Mimic other object's rotation on one axis (with offset) 0 Answers

Rotation of GameObject using iTween 1 Answer

iTween not precise? 1 Answer

itween path restrict rotation on TWO axis 0 Answers

Limit Rotation of Camera around a player using keyboard 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