Update: Frustrated as hell, that’s why I’m offering 4 (an average of $200) models of your choice from my website to whoever can give me a solution and fix this problem. This is a one time deal and only goes for the person that gets this working for me.
More Problems:
I have continued to mess with the settings and no luck. I am supposed to be using a network rigid body view right?? I even tested it with 4 players and on each player’s separate screens I controlled all four players but only with in the active screen. I am completely perplexed. I have no idea why it’s not working.
This is the only thing standing between getting my game to be publicly played. The modeling and scenery won’t take me long but the coding and networking is killing me. Please someone help me out this is the most frustrating thing. I’m surprised people haven’t had similar problems.
Original Post:
I used the M2H tutorial as starting point for creating an online multiplayer shooting game.
I plan to make a free to play 3rd/first person online shooter. I’m great at modeling and everything else except for programming. I’m not the best programmer. Once I get this bug/error out of the way I can really start making my game and its’ levels. I didn’t want to start the real modeling until I was certain I could get this problem fixed.
Whats hard about my game is that I completely redid my character because I’m doing a 3rd/FPS shooter game.
Everything works fine, I connect both players online and I can chat with the other player. Then when I control my player I also control the other player that is online and vise versa. I have done everything that the other prefabed player did on the m2h example and still no luck. Is there something simple I’m missing or is there something I didn’t do right?
How can I make it so the players are controlled separately?
I don’t really know how to give you an example I’ll take a screen of my character.
As you can see below there are 2 completely different games running even though I’m connected to the same network. You can tell by the crates in the back. I’m really confused and I don’t know what’s causing this.
i think you have the authoritative setup so the server instantiates both players and controls them. in the example the server sends an rpc to the client telling it to take control of the player.
maybe you missed that part.
Alright thanks for the suggestions I’ll try them both.
As for coding I don’t know much so I wouldn’t know where to put that if statement. I also wouldn’t know how to make the machine gun script work over the network. The one that’s in the tutorial is okay but it lacks effects.
I’m using the one from TwiiK’s Third Person Learning Project but it was a pretty basic script just liked the bullet hole effects. So should I just use machine gun from M2h’s tutorial?
Also why do I control both players it’s the most frustrating thing. Where would I add the encompassing if statement? What I don’t get is that the player are on completely different levels even though they connect through the server. Does it have anything to do with animations over a network?
Thanks again for the suggestions I really hope I can get this fixed.
Like i said before, if the server (in an authoritative setup) instantiates the players, he is the owner and therefore has control over them.
Thats why it’s authoritative, a way for the server to prevent cheating. The players get control after the server has told them to control the gameobject.
Look for the script where you get that call.
The networkView.isMine should be called there.
If you are using the FPSWalker script from the example, try putting the if statement as the first line in the FixedUpdate() function. Open it there and close it right before the end of the function.
/*
* This file is part of the Unity networking tutorial by M2H ([url]http://www.M2H.nl[/url])
* The original author of this code is Mike Hergaarden, even though some small parts
* are copied from the Unity tutorials/manuals.
* Feel free to use this code for your own projects, drop us a line if you made something exciting!
*/
#pragma strict
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if(networkView.isMine){
}
if (grounded) {
if(!FPSChat.usingChat){
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
//@script RequireComponent(CharacterController)
/*
* This file is part of the Unity networking tutorial by M2H ([url]http://www.M2H.nl[/url])
* The original author of this code is Mike Hergaarden, even though some small parts
* are copied from the Unity tutorials/manuals.
* Feel free to use this code for your own projects, drop us a line if you made something exciting!
*/
#pragma strict
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if(networkView.isMine){
if (grounded) {
if(!FPSChat.usingChat){
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
}
//@script RequireComponent(CharacterController)
You need to place all the code inside of the first if statement or else it will continue to run the code regardless.