Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sbsmith · Aug 19, 2016 at 06:13 PM · transformcharacter controllermirror

CharacterController does not transform as expected

This is a question that I'll be answering myself just because it caused so much trouble that I want a resource out there for other people who run into the same problem.

I have a character with an Animator (with root motion) and the CharacterController component provided by Unity. I want to flip it upside down so that the top of its head is touching the same point. So, a 180 degree rotation on the facing axis around the top of its head.

The character is 1 unit tall, so the Vector3.up below is just a shorthand for a point, it's not a vector.

 if( Input.GetKeyDown( KeyCode.Space ) )
 {
     Vector3 rotateAround = transform.localToWorldMatrix.MultiplyPoint( Vector3.up );
     Matrix4x4 flip = CreateRotationMatrixAroundPoint( rotateAround, Vector3.right, 180f );
     Quaternion flipRot;
     ExtractRotationFromMatrix( flip, out flipRot );

     transform.position = flip.MultiplyPoint( transform.position );
     transform.rotation = flipRot * transform.rotation;
 }

Instead of the feet appearing at twice his height with his head down. The feet are appearing at twice his height with his head up.

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
Best Answer

Answer by sbsmith · Aug 19, 2016 at 06:13 PM

If I was moving a normal object, the code above would work. However, with the Character Controller, the order in which the position and rotation are changed makes a difference. Simply place the rotation code above the position code and you get the expected behaviour.

 if( Input.GetKeyDown( KeyCode.Space ) )
 {
     Vector3 rotateAround = transform.localToWorldMatrix.MultiplyPoint( Vector3.up );
     Matrix4x4 flip = CreateRotationMatrixAroundPoint( rotateAround, Vector3.right, 180f );
     Quaternion flipRot;
     ExtractRotationFromMatrix( flip, out flipRot );

     //transform.position = flip.MultiplyPoint( transform.position );
     //transform.rotation = flipRot * transform.rotation;
     
     transform.rotation = flipRot * transform.rotation;
     transform.position = flip.MultiplyPoint( transform.position );
 }
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

57 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

Related Questions

Movement Script Bug 0 Answers

Unity/Mirror Network Delay After Transferring Client Authority 1 Answer

mirror object based on parent transform 1 Answer

Character Controller Crouch With transform.localScale Problem. 1 Answer

How can i write this Code with Character Controller -1 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