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 hasseyg · Nov 10, 2014 at 03:12 PM · rigidbodyrotateaxisglobal

Rotate rigidbody using MoveRotation() around the global y axis

Hi, I originally had this code to rotate my game object which worked fine:

 transform.Rotate (new Vector3 (0, joytickX, 0), Space.World);
 transform.Rotate (new Vector3 (joystickY, 0, 0), Space.Self);

But then I realised I needed to rotate the rigidbody instead so I changed it to this:

 Quaternion deltaRotation = Quaternion.Euler (new Vector3 (joystickY, joytickX, 0));
 rigidbody.MoveRotation (transform.rotation * deltaRotation);

The problem is that MoveRotation() rotates the game object using it's local space, of which is fine for the x axis but for the y axis I want it to rotate using the global space instead. How can I achieve this whilst still using MoveRotation()?

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 hasseyg · Nov 10, 2014 at 05:24 PM 0
Share

Ok not to worry I have solved it with a workaround. I just made an empty game object called direction of which i use the old transform.rotation code i originally used and in fixedupdate i just use the following line :

rigidbody.$$anonymous$$oveRotation (Quaternion.LookRotation (direction.forward));

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by lgarczyn · Jan 18, 2020 at 06:55 PM

Old post, but it shows up on Google, so:

the problem was the order of the multiplication. The left-most operand is the one on the outside, and the right-most operand is on the inside.

The only reason your rotation was "local" is because you used the wrong multiplication order in MoveRotation.


 rigidbody.rotation * deltaRotation

will add deltaRotation to the current rotation. If your local Y axis is on its side, it will rotate around it.

  deltaRotation * rigidbody.rotation

will rotate around the world Y axis instead, then restore your current rotation

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

Answer by robertbu · Nov 10, 2014 at 03:17 PM

You could use Quaternion.AngleAxis():

  Quaternion deltaRotation = Quaternion.AngleAxis(joystickX, transform.up) * Quaternion.AngleAxis(joystickY, Vector3.right);

Without testing, I don't know the exact recipe. You may have to reverse the order the two rotation are combined and/or negate one the angle.

Also I'd reverse the order in the MoveRotation():

   rigidbody.MoveRotation (deltaRotation * transform.rotation);


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Constrain Turret Rotation while child of Rigidbody 2 Answers

use world axis when using transform.rotate 3 Answers

use world axis when using transform.rotate 0 Answers

Rotating Player Controller locally or globally. 0 Answers

how to tilt boat on turning 2 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