[Noob] Help with Photon - Wrong character controlled.

Hi everybody.
First of all I wanna thank you for this supercool network engine.
I have an issue setting it up Photon: no compile errors, but if I get in game with more than one client, if I try to move with my character, I could also see the other one moving.
I lost 3 days trying to figure how to solve this, with no clues.

So, I have 2 scripts, NetworkManager.cs and NetworkCharacter.cs.

Photonview on my player controller is observing NetworkCharacter.cs (if I observe player transform it will teleport around the map like flash gordon)

[code2=csharp]using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour {

public GameObject standbyCamera;
SpawnSpot[] spawnSpots;

// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
Connect ();

void Connect() {
PhotonNetwork.ConnectUsingSettings( "LASERFPS v001" );

void OnGUI() {
GUILayout.Label( PhotonNetwork.connectionStateDetailed.ToString() );

void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");

void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );

void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");


void SpawnMyPlayer() {
if(spawnSpots == null) {
Debug.LogError ("WTF?!?!?");

SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);

//((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true;
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);

NetworkCharacter.cs (actually I tried also with a copy+paste from the marcopolo tutorial code, with same results)
[code2=csharp]using UnityEngine;
using System.Collections;

public class NetworkCharacter : Photon.MonoBehaviour {

Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;

// Use this for initialization
void Start () {


// Update is called once per frame
void Update () {
if( photonView.isMine ) {
// Do nothing -- the character motor/input/etc... is moving us
else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
// This is OUR player. We need to send our actual position to the network.

else {
// This is someone else's player. We need to receive their position (as of a few
// millisecond ago, and update our version of that player.

realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();


This is from a FPS tutorial by quil18 on youtube. He has kinda the same problems setting it up, but this should be the working code. (at least, it works for him)

Am I missing something?


  • SOLVED (understanding why)

    I did it again from scratch (with pretty much the same code) but now is working fine.

    What was the error?
    I did forget to disable PlayerMovement.cs from the player controller… :oops:

    Thanks anyway! :D
  • You're welcome! ;)
Sign In or Register to comment.