Problem with networkView.isMine

Hi, i’m making an online fps and i’ve some problems with moving only my pg.

I use this code :

if(networkView.isMine){

// Move scripts

}

When i start the server the play that is created moves correctly, but when i connect another player, this player can’t move and when it try to move, it moves the first player created, the same think happen to the first player, when i try to move it only the second moves.

Moviments are reversed after that the second player is created!!

I don’t think that the code is wrong…

What i have to do?

Anyone know what is the problem?

Hard to tell without code, can you post it so we can have a look ?
Can you also tell us how you instantiate your players ?

I istantiate the players with Network.Instantiate The code is an if that include the code for the movements only if the network view is mine…

Hi marf - I can’t 100% say for sure that this is the solution as we don’t know what your movement scripting consists of, but I solved this problem for my game by disabling the Camera component of any instantiated Player that doesn’t belong to the controlling Player on Awake()

In the script that handles my Player movements I have this:

public void Awake() 
{
        if (!networkView.isMine)
        {
	     GetComponentInChildren<Camera>().enabled = false; // disable the camera of the non-owned Player; 

	     GetComponentInChildren<AudioListener>().enabled = false; // Disables AudioListener of non-owned Player - prevents multiple AudioListeners from being present in scene.
         }
}

marf, when do you instantiate your player, in what function ? OnClientConnected or OnConnectedToServer ?

I instantiate thev player in function OnConnectedToServer() and function OnServerInitialized() so, when i client connect or the server isinstantiated.

This is spawn code:

var playerPrefab : Transform;

function OnConnectedToServer()
{
	Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}


function OnServerInitialized()
{
	Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
}

function OnPlayerDisconnected (player : NetworkPlayer)
{
	Debug.Log("Server destroying player");
	Network.RemoveRPCs(player, 0);
	Network.DestroyPlayerObjects(player);
}

@dlcl I attached this in the inspector, but nothing happens…

No one?

In the answer: Networking Script Controls the Opposite Player - Questions & Answers - Unity Discussions there is the same problem, but i don’t understand the solution… Someone can help me?

I have the same problem…

It sounds like a Camera issue are you creating cameras with the player prefab? if so then you need to turn off the camera then enable if

pseudo code

function start
if networkView.isMine()
cam.enabled = true;
else
cam.enabled = false;

this should fix any camera issue you have because I had the same problem in my game back in the day… well a year ago check it out though:

My video : http://www.youtube.com/watch?v=Ayn9BcoKVIY

you are describing a problem in your script for player control - where you need to have the client control his locally network.instantiated player and any players that connect and create a remotely network.instantiated player is controlled remotely.

Your reply with code to appels about where/when you are doing the instantiating seems ok (although I do it in a OnNetworkLevelLoaded function as in the Unity networking example project.)

NetworkView.isMine only returns true if the object was instantiated locally, so that would seem to suggest more than one player is being locally instantiated and therefore input control moving to that one, but otherwise there does not seem to be enough to go on in what you have provided to take a guess.

The third-person multiplayer example in Unity’s networking example project is about as bare bones of an an example as you can get, and the network.instantiating and player control using NetworkView.isMine all work as expected. You might try drilling through that project and find where you might be missing something.