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 BushElito · Aug 13, 2016 at 09:13 AM · animationrotationbone

Bone rotation overrides animations completely

So I am making a FPS multiplayer game and got stuck at synchronizing animations. After delving into why it didn't work, I have noticed that it is because of mouse look and bone rotation.

I had this problem before and did find the solution that worked back then. Weirdly, it no more works for me. Other threads/posts didn't really help or were different topics, or were too old.

I can confirm that the animations do work, the model is rigged up correctly and nothing else interferes. It seems only the bone rotation messes up the animation and it simply doesn't play, because they started to work and sync across clients after I commented up the script part.

In short, if I'm rotating the bones with script, animations don't play, if I don't rotate, they play. I suspect I have some kind of bug in my code.

Here is the animation controller script I use:

 private float rotationX;
 private float rotationY;
 private float rotationZ;
 
 void LateUpdate()
     {
         BodyPartRotation(rotationX);
         if (!isLocalPlayer)
         {
             return;
         }
         var newrotationX = -m_Camera.transform.eulerAngles.x;
 
         CmdBodyPartRotation(newrotationX);    
     }
 
     [Command]
     void CmdBodyPartRotation(float newrotationX)
     {
         BodyPartRotation(newrotationX);
         RpcBodyPartRotation(newrotationX);
     }
 
     [ClientRpc]
     private void RpcBodyPartRotation(float newrotationX)
     {
         if (!hasAuthority)
         {
             BodyPartRotation(newrotationX);
             return;
         }
         BodyPartRotation(newrotationX);
     }
 
     void BodyPartRotation(float newrotationX)
     {
         rotationX = newrotationX;
 
         Vector3 newRot = new Vector3(newrotationX, 0, 0);
         newRot = newRot + armLpos;
         armL.localEulerAngles = newRot;
         newRot = new Vector3(newrotationX, 0, 0);
         newRot = newRot + armRpos;
         armR.localEulerAngles = newRot;
         newRot = new Vector3(0, 90, -newrotationX);
         head.localEulerAngles = newRot;
     }

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 BushElito · Oct 10, 2016 at 08:20 AM

So it seems instead of

     Vector3 newRot = new Vector3(newrotationX, 0, 0);
     newRot = newRot + armLpos;
     armL.localEulerAngles = newRot;
     newRot = new Vector3(newrotationX, 0, 0);
     newRot = newRot + armRpos;
     armR.localEulerAngles = newRot;
     newRot = new Vector3(0, 90, -newrotationX);
     head.localEulerAngles = newRot;

I did

     armL.localEulerAngles += new Vector3(0, -newrotationX, 0);
     armR.localEulerAngles += new Vector3(0, -newrotationX, 0);
     head.localEulerAngles = new Vector3(0, -newrotationX, 0);

Which apperantly works, but only for the client. It starts to jitter all over the place.

So, instead of telling all clients to rotate the bone, I instead made it to change the angle of the bone in the ClientRPC method.

I'm not sure if it is a good thing to do, but it seems to work flawlessly like that.

So, in other words (or in code)

  private float rotationX;
  private float rotationY;
  private float rotationZ;
  
  void LateUpdate()
      {
          
          if (!isLocalPlayer)
          {
              //new!
              //we moved this into here because we aren't going to use rotationX for the local client
              BodyPartRotation(rotationX);
              return;
          }
          var newrotationX = -m_Camera.transform.eulerAngles.x;
  
          //new!
          //we instead put here, while using the newrotationX, because htis is the local client
          BodyPartRotation(newrotationX);
  
          CmdBodyPartRotation(newrotationX);    
      }
  
      [Command]
      void CmdBodyPartRotation(float newrotationX)
      {
          RpcBodyPartRotation(newrotationX);
      }
  
      [ClientRpc]
      private void RpcBodyPartRotation(float newrotationX)
      {
          if (!hasAuthority)
          {
              //new!
              //change the value instead of change the bone.
              rotationX = newrotationX;             
          }
      }
  
      void BodyPartRotation(float newrotationX)
      {
         var pos = new Vector3(0, -newrotationX, 0);
 
         //new!
         //instead of changing, we add it to the actual value
         armL.localEulerAngles += pos;
         armR.localEulerAngles += pos;
         head.localEulerAngles = pos;
 
         //I moved this to the bottom of the method just for the sake of it.
         rotationX = newrotationX;
      }
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

Animation interfears Player-Movement 1 Answer

Strange rotation going crazy when recording animation 2 Answers

Rigging Question: Location of Root bone 0 Answers

Rotate a bone with mouse input while animation is playing 0 Answers

Help: Making an object face a target 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