- Home /
Photon First Person Controller
Hello!
I am trying to make a FPS multiplayer game using Photon but I am getting a problem trying to receive the CharacterMotor script (so that I call the .canControl = false so other players can't control my player and vice versa) which is in java/unityscript and I am writing this code in c#. I have understood that this probably is the problem and I have red about this in so many forums and tried moving the CharacterMotor script to other folders to make it compile first but it just won't work. Atm the other players just keep jumping to a fixed point ((0,0,0) I think) all the time and I believe it's because the CharacterMotor is still active on other the other players. Any help would be much appreciated as I am almost starting to pull my hair out over this. Thanks in advance! :)
Here is the code:
using UnityEngine;
using System.Collections;
public class FirstPersonNetwork : Photon.MonoBehaviour {
private MouseLook cameraScript1;
private MouseLook cameraScript2;
private CharacterMotor ControllerScript; //Can't find it here
private Transform thisTransform;
private GameObject thisObject;
private GameObject camera;
void Awake(){
thisTransform = this.gameObject.transform;
thisObject = this.gameObject;
camera = thisTransform.FindChild("Main Camera").gameObject;
cameraScript1 = thisTransform.GetComponent<MouseLook> ();
cameraScript2 = camera.transform.GetComponent<MouseLook> ();
ControllerScript = thisTransform.GetComponent<CharacterMotor> ();
if (photonView.isMine) {
camera.camera.enabled = true;
camera.GetComponent<AudioListener>().enabled = true;
cameraScript1.enabled = true;
cameraScript2.enabled = true;
ControllerScript.canControl = true;
}
else{
camera.camera.enabled = false;
camera.GetComponent<AudioListener>().enabled = false;
cameraScript1.enabled = false;
cameraScript2.enabled = false;
ControllerScript.canControl = false;
}
thisObject.name = thisObject.name + photonView.viewID;
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting) {
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
private Vector3 correctPlayerPos = Vector3.zero;
private Quaternion correctPlayerRot = Quaternion.identity;
void Update(){
if (!photonView.isMine) {
thisTransform.position = Vector3.Lerp(thisTransform.position, correctPlayerPos, Time.deltaTime * 5);
thisTransform.rotation = Quaternion.Lerp(thisTransform.rotation, correctPlayerRot, Time.deltaTime * 5);
}
}
}