|
Hello everyone ! I'm confronted to the famous multiplayer cameras problem (I saw a lot a questions about this, but couldn't solve mine...) for my FPS game. I want to instantiate a player prefab for each client and the server. I need (locally) to attach the main camera to my player prefab, in a specific place of the model. Here is the code attached to a gameobject NetworkManager, empty, in my scene : I have a Network View attached to my player prefab. This is actually not working at all :). My camera stays still and does not follow my character, in debug mode I can clearly see that I go into the "if" loop. Does someone has an idea of the problem ?
(comments are locked)
|
The question has been closed Aug 29 '12 at 05:06 PM by KiraSensei for the following reason:
The question is answered, right answer was accepted
|
Attach a network view component to your camera, and then attach the following script to it as well. I added this script to my main camera, and attached this camera to my prefab, so I don't need to move it and change the parent anymore. I still have a big problem : Failed Network.Instantiate because we are not connected. And the result is, I have only one character, and moving only from one of the 2 instances, the other instance is "following". I have no idea why there could be a connection problem.
Aug 27 '12 at 06:41 PM
KiraSensei
Forgot to tell that the error is because of line : var playerInstance:GameObject = Network.Instantiate(player, spawnPos[pos].position, Quaternion.identity, 0);
Aug 27 '12 at 09:51 PM
KiraSensei
I forgot to say to attach it to your player camera not your main camera. Sorry for the confusion ;)
Aug 28 '12 at 11:37 AM
valax
I think your code above should be in OnNetworkInstantiate() instead of Start(). You'd also probably want to do more than simply disable the camera.
Aug 28 '12 at 03:34 PM
SomeGuy22
Hi SomeGuy22, can you be more specific in : "You'd also probably want to do more than simply disable the camera." ? What should I do too ?
Aug 28 '12 at 08:48 PM
KiraSensei
(comments are locked)
|
|
You were asking more than just disabling the camera, take a look at this code: There's a lot of stuff that needs to be adjusted in order for the game to separate the player from another player. The NetworkInterpolatedTransform script is what keeps the other player's movement shown on your computer. I understand. I did what you told me, and this is quite better, thanks ! But I still have some weird things happening : when I instantiate the first character, no problem, when the second one is instantiated, it takes the first one position, and the second is somewhere else (I have a spawn script with random positions). More problematic : when I move, it moves the other player, and not mine, only mouse look is connected to the good player :(. This is with your if/else code, adapted to my 3D model.
Aug 28 '12 at 10:54 PM
KiraSensei
Ok forget my mouse look problem, that was something else and it is corrected, but I still have the mixed controls problem : I tested that if I do : if ( ! networkView.isMine) // !!! NOT isMine { GetComponent(MouseLook).enabled = true; GetComponent(FPSInputController).enabled = true; } ..... It does not work when I am alone, but it is normal when there are two players :( How can they switch like that ?? EDIT : if I disconnect the second player, the first one goes back to its normal position O.O Raaaaah I don't understand anything to networking :'(
Aug 28 '12 at 11:31 PM
KiraSensei
Haha that's how I felt when I first started. Take a look at this example project, it's how I learned: http://unity3d.com/support/resources/example-projects/networking-example
Aug 29 '12 at 01:51 AM
SomeGuy22
Also the reason your characters are moving is because you a NetworkInterpolatedTransform (found in the example) and it needs to only activate on the player that spawns.
Aug 29 '12 at 01:52 AM
SomeGuy22
(comments are locked)
|
