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 redteardrop · Oct 06, 2012 at 02:57 AM · rotationtransformeuleranglesrotatearound

Rotation promlems past 90 and 270

Problem with rotation and I can't seem to fix it. Here is what I am using:

function Update()
{
transform.rotation.x += 20* Time.deltaTime;
}
or
function Update()
{
transform.RotateAround (transform.position, Vector3.right, 20 * Time.deltaTime);
}
What happens with the first one is it gets to a point and stops moving. The numbers on rotation x seem to stick around 0-1 without actually stopping. The rotate around script animated the object correctly, but the rotation of x goes up from 270 to 90, then counts back down to 270 after flipping the Y and Z rotation from 0 to 180. If I rotate manually in play mode and switch to the scene view to rotate using tools, it does the same thing. If I am trying to use something to match the rotation, it's fine for half the rotation on the x axis, but once it gets past the 90 and starts counting back down it messes it all up. any idea why it does this?

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

3 Replies

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

Answer by Eric5h5 · Oct 06, 2012 at 05:50 AM

Transform.rotation is a 4D quaternion, and rotation.x does not correspond to the x axis. Use Transform.Rotate instead. There is more than one valid way to represent a quaternion as euler angles (e.g. 0,0,0 is identical to 180,180,180), so reading one axis by itself is somewhat meaningless.

Comment
Add comment · Show 2 · 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 redteardrop · Oct 06, 2012 at 03:05 PM 0
Share

That just seems overly complicated. I am used to 3D Game Studio and there are several advantages to it than Unity, but Unity is better for cross platform and the AAA stuff being built in. Being able to use a .sav file for instance is one such advantage, I tried your solution, and it kinda works, but still having some issues.

transform.Rotate(Vector3.up * Time.deltaTime *20, Space.World);
This works great, the x and z axis stay put no problem and the y just goes from 0 - 360 and just keeps looping. Now:
transform.Rotate(Vector3.right * Time.deltaTime *20, Space.World);
this is a problem. The same issue happens where the y and z flip 180 and the x bounces back and forth. I'm beginning to think I just need to ignore the x axis and rotate my prefab to use the Y as it's primary. (It's a 2d game with 2 of the axis locked anyway). Here's the main issue though. Why is this only an X axis problem? I made a cube in scene view and added nothing but the rotate script above and the problem should be easily reproducible. I may need to figure out the X at some point but I think using Y might work fine too.

avatar image Eric5h5 · Oct 06, 2012 at 04:33 PM 0
Share

As I said, there's more than one valid way for a quaternion to be represented as euler angles, so the individual axis numbers are kind of meaningless. It doesn't matter that the y and z flip 180. It has no effect on how Rotate works; it's just a side effect of conversion since quaternions are used internally. Nothing is wrong.

avatar image
1

Answer by Dragonlance · Oct 06, 2012 at 03:19 PM

Tried to put it in an empty object an then rotate in local space:

transform.Rotate(Vector3.right * Time.deltaTime *20, Space.Self);

That should do it.

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 redteardrop · Oct 06, 2012 at 03:26 PM 0
Share

Nope, doesn't work for me. I already tried it with both Self and World. $$anonymous$$aybe it's just my install? Using 3.5.5f3 standard ed. and have not changed any of the default physics or anything else.

avatar image Dragonlance · Oct 06, 2012 at 07:51 PM 0
Share

And you have put your model into an empty object? This piece of code on the $$anonymous$$odel?

It works for me.

avatar image redteardrop · Oct 07, 2012 at 03:30 PM 0
Share

no, the model is not in an empty object. The latest test I did was just create a cube in the engine and attache the script directly.

avatar image
0

Answer by Chouat.mohamed · Apr 14, 2015 at 05:27 PM

Hello , try to fixe your zone of work , 0 to 90 0 to 180 or 0 to 360

and se ur variable like this

alpha =((transform.eulerAngles.x%360)%180)%90;

So here the % have a role to find the angle betwen 0 and 90 180 360 .....

2kpi in math

Comment
Add comment · 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

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

12 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

Related Questions

Problems caused by non-unique Euler angle solutions 1 Answer

Rotate Around Planet with Spaceship Face Set on Path 1 Answer

Error with transform.RotateAround when I use a variable for the last parameter... 1 Answer

Object wont rotate in the opposite direction 1 Answer

How do you smoothly transition/Lerp into a new rotation? 3 Answers


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