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
1
Question by UnityNoob123 · Apr 20, 2018 at 07:24 PM · networkingtransformmeshbone

Sync player bone/skin renderer with unet?

So I have a player model, and I would like to sync the head movement with the camera on the network, which is already working locally. For the head movement I just set the head bone's rotation.y to the camera's rotation.y (using euler angles and quaternions). So my question is, would it be possible to sync that rotation over the network without separating the mesh into two meshes for the head and body? Any help is appreciated and thanks for your time!

 public GameObject headBone;
 [SerializeField]
 private Camera cam;
 
 private void LateUpdate() {
         RotateHead();
     }
 
     void RotateHead() {
         Vector3 _camRot = cam.transform.localRotation.eulerAngles;
         Quaternion _newRot = Quaternion.Euler(0, _camRot.x, 0);
         headBone.transform.localRotation = _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
1
Best Answer

Answer by UnityNoob123 · Apr 22, 2018 at 06:44 PM

So basically if anyone stumbles upon this in the future, to sync the bone rotation I used a command and an rpcclient call and passed in the calculated rotation, and set the head bone gameobject inside those two calls. However this worked, it made the characters head glitch over the network because if the Rpc call was late or never happened due to network lag, the players head would try to snap back to its original rotation because of the animation that was playing. To fix this I saw an old post from 2013 which basically said to make a gloabal variable for rotation, and set that variable in the command and rpc calls, but in the regular function, set the head rotation to that global variable so that way the clients and network calls "see" the same rotation. Also note, you cannot disable this script for other clients, since the connected clients need to run the head rotation function every frame to avoid the head from glitching. I hope this helps someone!

 public GameObject headBone;
     private Quaternion headRot;
     [SerializeField]
     private Camera cam;
     
     // Update is called once per frame
     void FixedUpdate () {
         PerformMovement ();
         PerformRotation ();
     }
 
     private void LateUpdate() {
         RotateHead();
     }
 
 
     //This script cannot be disabled because the clients need to be updated every frame
     void RotateHead() {
         float _currentCamRotX = cam.transform.localRotation.x;
         Vector3 _camRot = cam.transform.localRotation.eulerAngles;
         prevCamRot = _currentCamRotX;
         Quaternion _rot = Quaternion.Euler(0, _camRot.x, 0);
         headBone.transform.localRotation = headRot;
         if (isLocalPlayer) {
             CmdProvideRotationsToServer(_rot);
         }
     }
 
     [Command]
     void CmdProvideRotationsToServer(Quaternion _rot) {
         headRot = _rot;
         headBone.transform.localRotation = _rot;
         RpcProvideRotationsToClient(_rot);
     }
     
     [ClientRpc]
     void RpcProvideRotationsToClient(Quaternion _rot) {
         headRot = _rot;
         headBone.transform.localRotation = _rot;
     }
 
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 planny · Sep 26, 2018 at 11:49 AM 0
Share

Absolute legend. Been stuck on the problem looking everywhere for days but this works perfectly. Thank you so much!

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

143 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

Related Questions

How can I get objects with local authority in my scene to update their positions when running networked? 1 Answer

Child transform of player object not syncing with server 2 Answers

Network Movement Sync Very jumpy. 0 Answers

How do i find a bone on my character within a script? 2 Answers

How to modify enemy players meshs with Photon Unity Networking? 1 Answer


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