Local multiplayer?

Hi, I’m working on a multiplayer game, and unfortunately while the rest of the gameplay is coming together fine, I’m having trouble with the multiplayer part.

I don’t really want to mess with the networking features, as that sounds a bit difficult (and I want to be able to play offline), so I was going to go with trying to create local multiplayer.

See, I want there to be a variable number of players, from 2-4. I want to instantiate the players based on that. So far so good (more or less).

Preferably, I want to use the same basic prefab and the same control scripts for all 4 players, but set each instance to accept input from a specific joystick. That’s the part I’m having trouble with. The way input is set up, I apparently have to set up separate axes for each joystick, and call them in the scripts, so I don’t see how one control script could work for all 4 controllers.

Any help would be much appreciated.

I also plan on attaching different components to each player depending on which character they choose, but I think I can figure that part out. I guess I could just forget about using the same control script and just make 4 separate ones, attaching the correct one at runtime. :\

EDIT: Nvmd, I think I figured it out. :stuck_out_tongue: I just had to Take the base name of an input axis and add a variable. like "Fire + “variable” for Fire4.

Weird. I’ve struggled with this problem for a while and the moment I go to make a thread I realize what I was doing wrong. Sorry to waste your time.

Okay, so now I am having a problem.

I created 4 of each input, with the same name plus a number for each joystick, then for each character I give them a player variable and just call “Axisname” + “player” as the input to ensure they receive control from the correct joystick.

This works fine for things like movement, but for some reason for animation it doesn’t work. If an input causes an animation to be played, all 4 “players” play the animation together. I don’t understand why that is.

For instance, lets say I have player 1. I use the following code to play a slash animation when he hits a certain button:

var Player = 1;

function Update () {
if (Input.GetButton ("Slash" + Player))
	{
	animation.Play ("slashing");
	}
}

“Player” is set to 1. Therefore, it should only call Slash1, and not Slash2, Slash3 or Slash4, right? But that’s exactly what it’s doing!

This problem is only with animation, not with movement, so I know at least the idea works. With movement it separates them out quite nicely.