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 Barabajagal · Oct 15, 2011 at 11:50 PM · rotationx-axis

Trouble Rotating an Object on x-axis

I am attempting to rotate an object on the x-axis, but every time it crosses the x-y plane it rotates 180 degrees on the y axis. I'm using a Vector3 called momentum to keep track of the direction the object is moving in, and after I rotate the vector I want to rotate the object to match the vector's rotation. I'm having no trouble with the y-axis, just the x. Here's the code.

     if (tup == 0){
         tup = Time.time;
     }
     var rotation = Quaternion.AngleAxis((-1*Mathf.Log(Time.time - tup + 1)),Vector3.right);
     momentum = (rotation * momentum);
     transform.localRotation = Quaternion.LookRotation(momentum);
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
0

Answer by aldonaletto · Oct 16, 2011 at 02:13 AM

I suspect that the cause of your problem is the following: LookRotation accepts a 2nd paramater, upwards, that define which is the up direction of the object. If not specified - like in your case - Unity assumes Vector3.up. When your object's forward direction passes 90 or -90 degrees (relative to horizontal plane) its "head" starts becoming upside down, so Unity flips it 180 degrees around y to keep its "head" up. You could just assign the calculated rotation to transform.localRotation, if your object has zero rotation initially. If it has some initial localRotation, save it at the beginning and combine the saved value with the calculated rotation before updating localRotation:

    // before start following momentum, save the initial rotation (at Start?)
    iniRot = transform.localRotation;
    ....
    // when calculating a new rotation:
    var rotation = Quaternion.AngleAxis(...);
    transform.localRotation = rotation * iniRot;
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 Barabajagal · Oct 16, 2011 at 03:08 AM 0
Share

I changed the code to match yours and I'm still experiencing the issue. I also tried setting the second parameter of LookRotation to Vector3.forward and transform.forward to no avail. I'm running into the same problem with a rotation the follows mouse movement that looks like:

rotX = transform.localEulerAngles.x; //initializes the mouse rotation

rotY = transform.localEulerAngles.y;

...

rotY = rotY + Input.GetAxis("$$anonymous$$ouse X")*100*Time.deltaTime;

rotX = rotX - Input.GetAxis("$$anonymous$$ouse Y")*100*Time.deltaTime;

transform.localEulerAngles= new Vector3(rotX%360,rotY%360,0);

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Making an object realistically rebound off walls 1 Answer

Animating (simple rotation) armature by script 1 Answer

How to make Main Camera shake correctly when getting attacked? 1 Answer

player rotation from the top with mouse position? 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