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 Arustyred · Aug 17, 2017 at 10:28 PM · rotationnetworkingissuesynchronization

Setting rotation of another player

Hello. I am making a multiplayer game and am trying to synchronize rotation of child gameobjects of each player but am having a couple issues. For example, if player one looks up, his head tilts back locally, but not over the network. I have a network Identity and network transform so when the player looks left and right, the whole player rotates locally and over network. However, network transform child doesnt work for the head, and i'm assuming that's because i have a rigidbody on it (so it can ragdoll on death). Therefore I made this script.

 using UnityEngine;
 using UnityEngine.Networking;

 public class NetworkSync : NetworkBehaviour {
 [SerializeField]
 private Transform neck;
 private Quaternion neckRotation;
 private Quaternion neckLastRotation;

 [SerializeField]
 private float lerpSpeed = 10f;
 [SerializeField]
 private float sendRate = 10;

 void Start(){
     neckLastRotation = neck.localRotation;
     InvokeRepeating ("UpdatePos", 0f, 1f / sendRate);
 }

 [Client]
 void UpdatePos(){
     if (!isLocalPlayer) {
         return;
     }
     neckRotation = neck.localRotation;
     if (!Network.isServer) {
         CmdUpdateServerRotation (neckRotation, neckLastRotation);
     } else {
         RpcSetRotation (neckRotation, neckLastRotation);
     }
     neckLastRotation = neckRotation;
 }

 [Command]
 void CmdUpdateServerRotation(Quaternion last, Quaternion newR){
     RpcSetRotation(last, newR);
 }

 [ClientRpc]
 void RpcSetRotation(Quaternion last, Quaternion newR){
     neck.localRotation = Quaternion.Lerp(last, newR, Time.time/lerpSpeed);
 }
 }

The gist of that is that it sends the heads rotation from last time the method was called and its current rotation to a command that calls an rpc that will lerp the head from the old rotation to the new one for all clients.

This works but after setting the rotation of the player's neck, it immediately sets it back. I think this is because players have local authority with the network identity script, but I have absolutely no clue how to fix this. Also, after a few minutes the server shuts down and sends these errors

Failed to send internal buffer channel:0 bytesToSend:42 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Send Error: WrongConnection channel:0 bytesToSend:42 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Any ideas what I can do? I've been on this for a few days and it's driving me insane.

Also I always have trouble making bodies of code, so if anybody could help me out with how to do spacing there, that would be nice too :)

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

0 Replies

· Add your reply
  • Sort: 

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

115 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

Related Questions

Network rotation is laggy and slow 2 Answers

Best Unet. 0 Answers

Unity NetworkTransformChild - Syncing the Child of a Child 0 Answers

Spawing Hololens Camera OR ARCamera at user defined spawn locations 0 Answers

Photon Network syncing the transform of a moving platform 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