Hi I make a billiard online game when i try to sync the transform.position from server to client have i problems by the collisons on the walls ther is to much space between them its lookt wirde and the other balls moves to early befor they touch some infos Unity version : 2017.3.0f3 Network : Unet Physic : Unity Physics all gameobjecs are 2d and on the server side this methods i Tried to sync the transform.position Unet NetworkTransform : looked laggy Vector3.lerp (transform, syncTransform, 0,3) : to much space between the collisons Sync the Velocity : looked good but the the position on both sides not the same and the asset Smooth Sync : looked okay but ther is to much space between the collison i dont really need realtime transmission i need more accuracy so i hope you can help me by this problem sorry for the bad english i am just a dumb german dude^ greetings Ice here some code that i use but its totaly S*** Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class TransformMotion : NetworkBehaviour { [SyncVar] private Vector3 syncPos; [SyncVar] private float syncYRot; [SyncVar] private Vector2 syncVelo; [SyncVar] private Vector2 syncColVelo; [SyncVar] private Vector3 syncColPos; //[SyncVar] private bool sync; private Vector3[] mySyncPos; private Vector3 distance; private float distance1; private Vector3 lastColPos; private Vector3 lastPos; private Quaternion lastRot; private Transform myTransform; private Rigidbody2D myRigibody2D; private Vector2 lastVelo; private bool test = true; private int ii = 1; private int j = 1; [SyncVar] private bool isMoving; [SerializeField] private float lerpRate = 10; [SerializeField] private float posThreshold = 0.5f; [SerializeField] private float rotThreshold = 5; // Use this for initialization void Start() { myTransform = transform; myRigibody2D = GetComponent<Rigidbody2D>(); mySyncPos = new Vector3[30]; mySyncPos[0] = syncPos; } // Update is called once per frame void FixedUpdate() { Cmd_SynVelo(); if (!hasAuthority) { lastVelo = myRigibody2D.velocity; } } void Cmd_SynVelo() { if (hasAuthority) { syncVelo = myRigibody2D.velocity; syncPos = transform.position; } // Debug.Log(Vector3.Distance(myTransform.position, syncColPos)); Debug.DrawLine(myTransform.position, syncPos); Debug.DrawLine(myTransform.position, mySyncPos[j], Color.red); if (!hasAuthority) { float power = Vector3.Distance(myTransform.position, syncPos); myTransform.position = Vector3.Lerp(myTransform.position, syncPos, 0.2f); Debug.Log(power); myRigibody2D.velocity = syncVelo; } } void OnCollisionEnter2D(Collision2D col) { if (hasAuthority) { syncPos = myTransform.position; syncColPos = transform.position; syncColVelo = myRigibody2D.velocity; Debug.Log("hit"); } if (!hasAuthority) { lastColPos = transform.position; if (transform.position == syncColPos) { myRigibody2D.velocity = syncColVelo; Debug.Log("SyncColVelo"); } // myRigibody2D.velocity = syncColVelo; } if (col.gameObject.name == "Dead") { Destroy(gameObject); // transform.position = new Vector2(Random.Range(-7, 7), Random.Range(-3, 3)); // gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(0,0); } } void OnCollisionExit2D(Collision2D col) { if (hasAuthority) { } if (!hasAuthority) { } } }
Yo yo, maker of Smooth Sync here. This was happening because it sends every so many seconds and if you hit the wall in-between the send rate, it will not send the position at the wall. I just finished adding a new feature that NetworkTransform doesn't have. You can call forceStateSendNextFrame() when you hit a wall on the host and then the position will be perfect. Import the new version from the store. Let me know if you have any difficulties.