Photon RigidBody2D Sync Problems
Options
Hello Unity Forums! I am currently having a lot of trouble with the syncing of Rigidbodies (2D), in my game, and I decided to follow a tutorial, but it seems I can't remove an error. This error says "Cannot implicitly convert type 'UnityEngine.Vector3' to 'float' " on line 48. How would I be able to solve this?
- using UnityEngine;
- using Photon.Pun;
- public class PUN2_RigidbodySync : MonoBehaviourPun, IPunObservable
- {
- Rigidbody2D r;
- Vector3 latestPos;
- Quaternion latestRot;
- Vector3 velocity;
- Vector3 angularVelocity;
- bool valuesReceived = false;
- void Start()
- {
- r = GetComponent<Rigidbody2D>();
- }
- public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
- {
- if (stream.IsWriting)
- {
- stream.SendNext(transform.position);
- stream.SendNext(transform.rotation);
- stream.SendNext(r.velocity);
- stream.SendNext(r.angularVelocity);
- }
- else
- {
- latestPos = (Vector3)stream.ReceiveNext();
- latestRot = (Quaternion)stream.ReceiveNext();
- velocity = (Vector3)stream.ReceiveNext();
- angularVelocity = (Vector3)stream.ReceiveNext();
- valuesReceived = true;
- }
- }
- void Update()
- {
- if (!photonView.IsMine && valuesReceived)
- {
- transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 5);
- transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 5);
- r.velocity = velocity;
- r.angularVelocity = angularVelocity;
- }
- }
- void OnCollisionEnter2D(Collision2D contact)
- {
- if (!photonView.IsMine)
- {
- Transform collisionObjectRoot = contact.transform.root;
- if (collisionObjectRoot.CompareTag("Player"))
- {
- photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
- }
- }
- }
- }
0
Answers
-
The question is a simple C# question but the problem is actually this: You can't convert a Vector3 into a single float. There are float values related to Vector3 (e.g. it's length) but ... which one do you need?
Us Photonians can not help here, sorry.
Maybe you can take a look at the built-in
PhotonRigidbody2DView
and figure out what's wrong?0