Trying to build controls that will allow a box within the scene to be moved by either the Host or Client. The box is different from the players because it has already been placed in the scene and is not being instantiated. I’m hoping to avoid instantiating the box, as it represents vehicles and other random objects that have been placed around the map.
::Current Script::
using UnityEngine;
using System.Collections;
public class tellToMove : MonoBehaviour {
bool firstUpdate;
Vector3 realPosition;
void Update () {
if (Input.GetKey (KeyCode.Keypad8)){
realPosition += Vector3.forward;
}
if (Input.GetKey (KeyCode.Keypad2)){
realPosition -= Vector3.forward;
}
if (PhotonNetwork.inRoom){
if(!firstUpdate){
firstUpdate = true;
realPosition = transform.position;
}
GetComponent<PhotonView>().RPC ("moveMe", PhotonTargets.AllBuffered, realPosition);
}
}
[RPC]
public void moveMe(Vector3 realPosition){
//print ("moveMe");
transform.position = Vector3.Lerp (transform.position, realPosition, Time.fixedDeltaTime);
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if(stream.isWriting){
//print ("Writing");
stream.SendNext(transform.position);
}
else{
//print ("Reading");
realPosition = (Vector3)stream.ReceiveNext();
}
}
}
With this, if I observe the gameobject transform with the attached photonView I’m able to move the box on either machine but it seems to be fighting with data ((jumps back and forth strangely)). If I observe the above script with photonView I can still move the box on either machine but now it only has a full range of motion with the Host, it seems the client can only move it x-distance from where the host left it, and both seem to jump strangely as before…
Unfamiliar with networking, I’m not sure how best to describe what I’m viewing, hopefully someone has an idea.