- Home /
The question is answered, right answer was accepted
Multiplayer first person camera
EDIT 10.12.2012:
I need still help with this (Copy - paste from comment):
Something is probably wrong with my logic, but I can't find it myself. (It works, but it's like inverted.. Player 1 can move player 2 and player 2 can move player 1.) My code is now like this:
@RPC
function Startgame(){
Application.LoadLevel("TestMap");
}
function OnLevelWasLoaded(){
if (networkView.isMine){
AddPlayer();
}
if (!networkView.isMine){
AddPlayer();
Destroy(camera1);
}
}
function AddPlayer(){
Network.Instantiate(playerPrefab, spawnObject.position,Quaternion.identity, 0);
}
Answer by Bunny83 · Dec 08, 2012 at 12:37 PM
You need to change the scripts on the player object. The playerobject has to check to whom it belongs and disable / remove components which shouldn't be there on the other clients.
Basically your controls have to be surrounded with:
if(networkView.isMine)
{
// control the player
}
And in Start of a script on the player object you should remove components like camera (which usually has the audiolistener as well)
So just make a public variable on the player script where you can reference it's own camera object (which should be a child of your player object):
var cam : GameObject;
function Start()
{
if (!networkView.isMine) // if this is not my player, remove the camera
Destroy(cam);
}
I got it working, but it's still inverted like with my old code. So Player 1 can move player 2 and player 2 can move player 1. What could be wrong?
The owner of an object (the owner is the only one that can actually update the state of the object across the network) is always the player that created the NetworkViewID which will be created when a NetworkView is instantiated. So the player calling Network.Instantiate will own the object.
Something is probably wrong with my logic, but I can't find it myself. (It works, but it's like inverted.. Player 1 can move player 2 and player 2 can move player 1.) $$anonymous$$y code is now like this:
@RPC
function Startgame(){
Application.LoadLevel("Test$$anonymous$$ap");
}
function OnLevelWasLoaded(){
if (networkView.is$$anonymous$$ine){
AddPlayer();
}
if (!networkView.is$$anonymous$$ine){
AddPlayer();
Destroy(camera1);
}
}
function AddPlayer(){
Network.Instantiate(playerPrefab, spawnObject.position,Quaternion.identity, 0);
}
Follow this Question
Related Questions
Multiplayer First Person controls other character? 0 Answers
Unity networking tutorial? 6 Answers
Sometimes when gone into game mode with the first person preset package, the controls won't work? 0 Answers
camera spectator mode multiplayer 1 Answer
Multiplayer - Standing Still Makes Player Disappear 0 Answers