How can I have one object be controlled by multiple clients?
Options
I have a button and I am trying to send it's transform across all clients, I am calling a RPC to tell when the button was pushed so I have that covered, but I need to visually show where the button because I am using physics to push it.
It seems that I can only send the position of the button from the main client, and for some reason send next is not working in this case. Is there a way I can set 'controlled locally' for all users?
It seems that I can only send the position of the button from the main client, and for some reason send next is not working in this case. Is there a way I can set 'controlled locally' for all users?
private Vector3 correctPosition = Vector3.zero; private Quaternion correctRotation = Quaternion.identity; void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(this.gameObject.transform.localPosition); stream.SendNext(this.gameObject.transform.localRotation); } else { correctPosition = (Vector3)stream.ReceiveNext(); correctRotation = (Quaternion)stream.ReceiveNext(); } } void FixedUpdate() { CurrentDistance = Vector3.Distance(this.transform.position, InitialPosition.position); if (CurrentDistance > MinDistance) { Vector3 PositionDelta = InitialPosition.position - this.transform.position; this.Rigidbody.velocity = PositionDelta * PositionMagic * Time.fixedDeltaTime; } else { this.gameObject.transform.localPosition = Vector3.zero; } transform.localPosition = Vector3.Lerp(transform.localPosition, correctPosition, Time.deltaTime * 5); transform.localRotation = Quaternion.Lerp(transform.localRotation, correctRotation, Time.deltaTime * 5); }
0
Comments
-
as i think in fixed update you need to check if photonview.ismine if you are owner - > you can move the object and OnphotonSerializeView will make that movement on clients side0
-
Thanks, but everyone is the owner of the button. I want to be able to have any one move the button and see it move when anyone else moves it, I tested it with what you suggested but still nothing.Grinch said:as i think in fixed update you need to check if photonview.ismine if you are owner - > you can move the object and OnphotonSerializeView will make that movement on clients side
0 -
With OnPhotonSerializeView, all clients synchronized to object owner values. To control object from non-owner, send RPC to owner asking to move the object.0
-
Thanks so much, I did realize that you have to take over request. Do you have a suggestion as to how to achieve a take over request, I was thinking every time a user interacts with an object it would request takeover, would you suggest this or something different?vadim said:With OnPhotonSerializeView, all clients synchronized to object owner values. To control object from non-owner, send RPC to owner asking to move the object.
0 -
You can switch object ownership. But I don't think that this makes much sense in your case. It's much easier to send RPC to current owner (master client?) to ask him update the button.1