• 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 Serge144 · Sep 26, 2020 at 02:45 PM · rotationquaternioncharacter movementrotatetowardseuler angles

Rotating player with Quaternion and RotateTowards

My 3D character is a Cow and can be pushed away by a collision, in which i'll apply a Force and Torque so that the character can be knocked back approprially. When the character enters collision, it goes into a 'Ball' position, in which it just rolls around like a ball. This i'm achieving already. However, now I wanted to rotate the Cow in such way that it is able to transition into the normal/walkable position. For example if the Cow is in the Ball position, with its belly up, facing forward in the World, i just want to rotate around the Z axis so that the belly is facing down, and now I can transition into normal/walkable position. I am already rotating the player, but for some reason, after rotation, the character ends up always facing forward in world coordinates but that's not what I wanted. I want that, if the character is facing to the right with the belly up, it will still face that direction but with the belly down. How can i achieve this? I think im close but can't get there.

 private IEnumerator StandUp() {
         float yRot = rb.rotation.y;
         Quaternion targetRotation = Quaternion.Euler(0, yRot, 0);
         Vector3 direction = targetRotation * Vector3.forward;
         while (Vector3.Angle(transform.forward, direction) > 1) {
             rb.rotation = Quaternion.RotateTowards(rb.rotation, targetRotation, 8f);
             yield return new WaitForSeconds(0.00f);
         }
         { ... } // animator controller -> set normal/walking state
     }
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 Serge144 · Sep 29, 2020 at 09:07 PM

Fixed it lol the yRot variable should be:

     float yRot = rb.rotation.eulerAngles.y;

Still some improvements to be made though, 10% of the times it doesn't fully go to the normal position and it rotates until it gets sideways (like it was sleeping).

EDIT Fixed the issue i mentioned above (of not going fully to the normal position), I changed the while condition to this:

 while (Quaternion.Angle(rb.rotation, targetRotation) > 2)
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

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

Related Questions

Child transforms screwed up by parent's rotations 1 Answer

How to convert quaternion to vector3 with specific multiplication order? 5 Answers

Rotating an object around the centre of its mesh, using Quarternion AxisAngle 1 Answer

How to rotate towards the mouse on one axis while snapping 0 Answers

Doing 2D only rotation using FromToRotation + RotateTowards 0 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