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!!
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.
}
}
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.