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 mrsev · Aug 21, 2017 at 03:10 PM · rotationquaternionnavmeshanglebone

Bone rotation in LateUpdate goes back to normal every frame

Hi everyone! I'd like to rotate a bone of a character following the mouseX Input. But the bone slowly goes back to its original position every frame, I'd like it to stay where it was rotated.

The character has a NavMesh moving him in like a cinematic scene where we can move the head.

Here's the code

     void Update()
     {
            rotX = Input.GetAxis("Mouse X") * sensitivity;
            (...)
     }    
     void LateUpdate()
     {
         //headRot is a float, head is the bone's transform
         headRot = head.transform.rotation.y+rotX;
         head.transform.localRotation = Quaternion.AngleAxis(headRot, new Vector3 (0,1,0));
     }

Comment
Add comment · Show 2
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 Destolos · Aug 21, 2017 at 05:16 PM 0
Share

It's not a solution to your problem, but when you want to rotate the head of your character, you could use the "LookAt" function of the Inverse $$anonymous$$inematics https://docs.unity3d.com/$$anonymous$$anual/Inverse$$anonymous$$inematics.html

avatar image mrsev · Aug 22, 2017 at 05:12 PM 0
Share

Hey, thank you. I didn't set up the I$$anonymous$$ system because they warn me that I need a humanoid armature correctly set in $$anonymous$$ecanim. But my Armature is custom made by me, and when I played with I$$anonymous$$ I didn't get any result, I probably just don't know how to set it up correctly...

2 Replies

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

Answer by mrsev · Aug 25, 2017 at 11:54 AM

Ok got it! It's stupid as F.

Before :

      void LateUpdate()
      {
          //headRot is a float, head is the bone's transform
          headRot = head.transform.localEulerAngles.y + rotX;;
          head.transform.localRotation = Quaternion.AngleAxis(headRot, new Vector3 (0,1,0));
      }

headRot is here taking the rotation as it is after the Update() function, which is the reset value of the default animation! Which is F-ing zero... So I just put that line after the last one in LateUpdate, so it takes the actual modified value. And works perfectly.

     void LateUpdate()
     {
         
         head.transform.localRotation = Quaternion.AngleAxis(headRot+rotX, new Vector3 (0,1,0));
         headRot = head.transform.localEulerAngles.y;
     }

Since I can't reward myself on the forum, I'll reward myself with a cookie. Cheers.

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
0

Answer by Destolos · Aug 23, 2017 at 06:24 AM

I guess, the problem is this code line headRot = head.transform.rotation.y+rotX; You use transform.rotation, the result is a Quaternion, but you want the eulerAngles and so you have to write headRot = transform.localEulerAngles.y + rotX;

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 mrsev · Aug 25, 2017 at 11:50 AM 0
Share

Thanks mate, it was apparently not the main problem, found it in the answer I post under. I kept the EulerAngles anyway cause it seems more correct.

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

91 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

Related Questions

reproducing hingejoint.angle 0 Answers

Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers

Rotate floor plane in-game via C# script 1 Answer

Bone Rotation on X (or any) axis Issues 1 Answer

problems with quaternion rotations 4 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