Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Imperium2 · Dec 13, 2015 at 05:39 PM · rotationnetworkingsynchronizationsyncsynchronize

Network Rotation not sync

My Unity version is 5.2.3f1, I m trying to sync the rotation of a child gameobject, in local works perfectly fine but it doesnt show up in other clients. I tried everything I could find and nothing.

The reason of this is to rotate a FPS body, so, I m trying to rotate Spine2 (Rotate the camera is not my best solution). I m using a Mixamo character to test, in the end I will have Mixamo auto-rigged charscters so everything I make here will be compatible.

I tried to use the Network Transform Rigidbody 3D and it only sync the character itself, not Spine2, I have tried Network Transform Child, and this: skeleton-sync.

In the script part, I have tried a lot of things, the most promising one was this:

 [SyncVar]
 private Quaternion syncPlayerRotation;

 [SerializeField]
 private Transform playerTransform;
 [SerializeField]
 private float lerpRate = 15f;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void LateUpdate () {
     TransmitRotations();
     LerpRotations();
 }

 void LerpRotations()
 {
     if (!isLocalPlayer)
     playerTransform.localRotation = Quaternion.Lerp(playerTransform.localRotation, syncPlayerRotation, Time.deltaTime * lerpRate);
 }

 [Command]
 void CmdProvideRotationsToServer(Quaternion playerRot)
 {
     syncPlayerRotation = playerRot;
 }
 
 [Client]
 void TransmitRotations()
 {
     if (isLocalPlayer)
     {
         CmdProvideRotationsToServer(playerTransform.localRotation);
     }
 }

Its from here

I attached it to Spine2 and still dont work, but when I attached it to the main character, it worked.

Also tried this:

 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     Vector3 syncPosition = Vector3.zero;
     if (stream.isWriting)
     {
         syncPosition = Spine.GetComponent<Rigidbody>().position;
         stream.Serialize(ref syncPosition);
     }
     else
     {
         stream.Serialize(ref syncPosition);
         Spine.GetComponent<Rigidbody>().position = syncPosition;
     }
 }

But I think it was for an older version of Unity.

To make the rotations I m using A Free Simple Smooth Mouselook

I edited it, this lines:

 if (Input.GetMouseButton(1))
         {
             var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.forward);
             transform.localRotation = xRotation;
 
         }
         else
         {
             var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);
             transform.localRotation = xRotation;
         }

Basicly, I changed Vector3.right to Vector3.forward and converted the Vector3.right only if the right mouse button is not pressed. The script is attached to Spine2 and its activated on the start if(isLocalPlayer) by script.

There's a pic of the current hierarchy: image (some cameras are there only to test, the main camera is FirstPersonCamera, extracted from the standard assets)

I noticed that if I debug log the Spine2 rotation, it only gives me values from 0 to 1.

Absolutely any response will be helpful, thanks!

ss2015-12-13at055632.png (10.9 kB)
Comment
Add comment · Show 1
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 Imperium2 · Dec 16, 2015 at 04:41 AM 0
Share

Finally I got it working, but only syncronize the player on the server, the client can see the rotations of the server character but the server can't see the client character rotation (tested with 3 clients too). I activate the script on other script with this:

 public override void OnStartClient()
     {
         Self.GetComponent<SimpleSmooth$$anonymous$$ouseLookSpine>().enabled = true;
     }

Self is the character. This is the script itself:

 [SyncVar]
 public Vector 3 rotation
 
     void LateUpdate(){
     
         if (isLocalPlayer)
         {
            ALL SimpleSmooth$$anonymous$$ouseLook stuff here
         }
         UseRotation();
     
     }
 
     [Command]
     public void CmdInitRotation()
     {
         rotation = Spine.transform.rotation.eulerAngles;
     }
 
     [Client]
     public void UseRotation()
     {
         if(isLocalPlayer) 
         {
             CmdInitRotation();
         } 
         else 
         {
            Spine.transform.rotation = Quaternion.Euler(rotation);
         }
     }

How can I make it to work on clients?

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by muzboz · Mar 30, 2016 at 09:37 AM

You probably want to use the components NetworkTransform and NetworkTransformChild appropriately on your objects.

I had troubles getting rotations to sync across the network, on child objects on my player (like the gun), until I discovered that I needed to put an extra NetworkTransformChild on the root player object, and drop the Weapon object onto that. Add another NetworkTransformChild to any children game objects that you need to sync position and rotation across the server!

All the best!

  • Murray

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 frankdervoelker · May 20, 2021 at 10:28 PM

Any news on this? I have a similar problem:

in the Update() method I move/rotate my player. I have NetworkTransformChild on his head (bone) to let the players head look around and everything works great and syncs over the network. (Mirror Networking Library)

BUT:

When I animate the player and character is walking I cannot deform bones because this deform will be resetted by the animator. So I found out that I can use LateUpdate() to deform the head bone. So in Update() the character is animated and in LateUpdate() the head is transformed. This works locally but is not synced over the network because Unity networking / mirror networking dont seem to sync this. Whats the right way to do this?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to sync a property?? 0 Answers

UNET Door sync 0 Answers

Unet Syncing Flashlights 2 Answers

Unity Mirror OnStartServer spawn GameObjects 1 Answer

In UNET how do I spawn players at specific point and rotation (2D) 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