Interaction Sync problem, need help :)

Options
Hello, a time ago, i had a problem with door interaction. On my server, only the master was able to interact with the door, i fixed it.
Now i have another, when the client interact with a door, it's very laggy and don't open properly (half way and start to freeze), same with the host when he close the door. I think this is a problem due to RPC but i don't find out what's the problem :/
It's my first time using networking
Can someone help me please ?

Video: https://youtu.be/na-Wv-cqyr4

Script i'm using:

using UnityEngine; using System.Collections; public class DoorInteractionMultiplayer : Photon.MonoBehaviour { public PhotonView pv; public float smooth = (float)2.0; public float DoorOpenAngle = (float)90.0; public float DoorCloseAngle = (float)0.0; public bool open = false; public bool enter = false; public string defined_key = "f"; public AudioClip OpenDoorSound; public AudioSource ASource; void Start() { //Create PhotonView this.gameObject.AddComponent<PhotonView>(); pv = PhotonView.Get(this); pv.observed = this; pv.synchronization = ViewSynchronization.UnreliableOnChange; pv.viewID = 7; } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { (enter) = true; } } void OnTriggerExit(Collider other) { if (other.gameObject.tag == "Player") { (enter) = false; } } void Update () { if (open == true) { pv.RPC("openDoor", PhotonTargets.AllBuffered, null); } else { pv.RPC("closeDoor", PhotonTargets.AllBuffered, null); } if (enter == true && Input.GetKeyDown(defined_key)) { open = !open; ASource.PlayOneShot(OpenDoorSound, 0.7F); } } [PunRPC] void closeDoor() { var target1 = Quaternion.Euler (transform.rotation.x, DoorCloseAngle, transform.rotation.z); transform.rotation = Quaternion.Slerp(transform.rotation, target1, Time.deltaTime * smooth); } [PunRPC] void openDoor() { var target = Quaternion.Euler (transform.rotation.x, DoorOpenAngle, transform.rotation.z); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); } }

Comments

  • clawd31
    Options
    @vadim I logged everything, i've i remove the close door function, the door open ! But i can't close it anymore xD
    How can I do that i'm completely lost x:X
  • clawd31
    Options
    I thinks it's because my 'open' var is not sync between my client and my server, so it's open on my client but not on my server (the server is closing the door because the bool 'open' is on false')
    How can I sync this var between client and server ?
  • vadim
    Options
    You can synchronize 'open' var as any other value: with RPC or with OnPhotonSerializeView.