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 awplays49 · Oct 12, 2015 at 11:21 PM · transformsyncsynchronize

Custom network transform only recognizing new position from the host

Hello!!!

Recently I decided to make my own network transform component to compensate for the lagginess.

Code:

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 
 [NetworkSettings (channel = 0, sendInterval =  0.033f)]
 public class NetworkTransformSync : NetworkBehaviour {
 
     public bool syncPosition;
     public bool syncRotationY;
     [SyncVar]
     private Vector3 syncPos;
     [SyncVar]
     private float syncRotY;
     public float lerpRate;
     
     void Update () {
         TransmitSync ();
     }
     
     void FixedUpdate () {
         LerpTransform ();
     }
     
     void LerpTransform () {
         if (!isLocalPlayer)
         {
             transform.position = Vector3.Lerp (transform.position, syncPos, lerpRate * Time.deltaTime);
             transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, syncRotY,  0), lerpRate * Time.deltaTime);
         }
     }
     
     [Command]
     void CmdSyncTransform () {
         if (syncPosition)
         {
             syncPos = transform.position;
         }
         if (syncRotationY)
         {
             syncRotY = transform.rotation.y;
         }
     }
     
     [ClientCallback]
     void TransmitSync () {
         if (isLocalPlayer)
         {
             CmdSyncTransform ();
         }
     }
 }

My only problem is, it only syncs positions to the host. The server does not receive positions and as a result thinks the player is always at 0 0 0. Help?

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 awplays49 · Oct 13, 2015 at 06:43 PM 0
Share

I've been stuck on this all day, It really would be nice if I could borrow a second pair of eyes on this :/

avatar image awplays49 · Oct 14, 2015 at 03:52 PM 0
Share

@meat5000 did you figure anything out because im really stuck on this UNET stuff :/ $$anonymous$$y productivity is limited right now to designing levels every day, and ive been helping others ins$$anonymous$$d of working.

I have another issue too. Other computers cannot connect to my server, and my computer cannot connect to other servers. this is a recurring issue i have had, on and off. If i could have some guidance, that guidance would be much appreciated.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Soahr · Nov 27, 2015 at 10:13 AM

Hi,

Thanks for the part of code. This help me so much for my dev. Hope this help !

 using UnityEngine;
 using UnityEngine.Networking;
  
 [NetworkSettings (channel = 0, sendInterval = 0.04f)]
 public class NetworkTransform_Custom : NetworkBehaviour {
     
     public float lerpRate;
     [SerializeField]
     Transform playerPrefab;
     [SerializeField]
     Transform playerCamera;
 
     [SyncVar]
     private Vector3 syncPos;
 
     [SyncVar]
     private float syncRotY;
 
     [SyncVar]
     private float syncRotX;
 
 
     void Update ()
     {
         TransmitSync ();
     }
      
     void FixedUpdate ()
     {
         LerpTransform ();
     }
      
     void LerpTransform ()
     {
         if (!isLocalPlayer)
         {
             playerPrefab.position = Vector3.Lerp (playerPrefab.position, syncPos, lerpRate * Time.deltaTime);
             playerPrefab.rotation = Quaternion.Lerp (playerPrefab.rotation, Quaternion.Euler (0, syncRotY,  0), lerpRate * Time.deltaTime);
 
             playerCamera.rotation = Quaternion.Lerp (playerCamera.rotation, Quaternion.Euler(syncRotX, playerCamera.rotation.eulerAngles.y, 0), lerpRate * Time.deltaTime);
         }
     }
      
     [Command]
     void CmdSyncTransform (Vector3 pos, float rotY, float rotX)
     {
         syncPos = pos;
         syncRotY = rotY;
         syncRotX = rotX;
     }
      
     [ClientCallback]
     void TransmitSync ()
     {
         if (isLocalPlayer)
         {
             CmdSyncTransform (playerPrefab.position, playerPrefab.rotation.eulerAngles.y, playerCamera.rotation.eulerAngles.x);
         }
     }
     
 }

For connection issues, make sure your ports are opened.

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

31 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

Related Questions

How to sync child objects of a transform in multiplayer 3 Answers

How to sync players in multiplayer game 1 Answer

Networking sync enabled state? 1 Answer

[UNET] TRANSFORMATION NOT SYNCING 0 Answers

Sync Var and transform 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