Hey so i want the photonview to send the rigidbody velocity and lerp it as well, since my animations are based off velocity, but i cant seem to get it to work :l
using UnityEngine;
using System.Collections;
public class Stream_loc_rot : Photon.MonoBehaviour {
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
// stream.SendNext((int)controllerScript._characterState);
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
//Network player, receive data
// controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
private Vector3 correctPlayerPos = Vector3.zero; //We lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
void Update()
{
if (!photonView.isMine)
{
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
}
}
}
using UnityEngine;
using System.Collections;
public class Stream_vel : Photon.MonoBehaviour {
animation anims;
public GameObject player_mesh;
void Start() {
anims = player_mesh.GetComponent<animation>();
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
// stream.SendNext((int)controllerScript._characterState);
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(rigidbody.velocity);
stream.SendNext((float)anims.jump_speed);
}
else
{
//Network player, receive data
// controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
correctPlayerVel = (Vector3)stream.ReceiveNext();
anims.jump_speed1 = (float)stream.ReceiveNext();
}
}
//private Vector3 correctPlayerVel = Vector3.zero;
private Vector3 correctPlayerVel = Vector3.zero;
private Vector3 correctPlayerPos = Vector3.zero;//We lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
void Update()
{
if (!photonView.isMine)
{
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, correctPlayerVel, Time.deltaTime * 5);
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
}
}
}