Game Development Community

Setting up A second player in the game Kit

by John Bura · in Torque X 2D · 10/13/2010 (2:34 pm) · 3 replies

So I have been trying to set up a second player in the gamekit but I cannot seem to get it to work. My method is to just copy one of the movement files and replace the following code with player 2. If I change the first line to player2, that should make it work but it doesn't.
_player = Game.Instance.Player2ControllerIndex; //Changed line
            PlayerManager.Instance.GetPlayer(_player).ControlObject = SceneObject;

            InputMap map = new InputMap();

            int gamepadId = InputManager.Instance.FindDevice("gamepad" + _player);

So if that is changed then all of these lines should work to (in theory)

map.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftThumbX, MoveMapTypes.StickAnalogHorizontal, 0);

Im clearly missing something. Does anybody have a tutorial on how to set up multiple players? :)

#1
10/13/2010 (3:24 pm)
if you run the debug, are the gamepadId, and _playerIndex correct?
#2
10/14/2010 (2:41 pm)
So I have managed to get this to work however when I play as player 1 it crashes, but when I play as player 2 it works fine.

Also When I play as player 2 it puts be as player 1. When I play as player 1 it puts me to player 2.

The Error I am getting is in this line

if (move.Sticks[0].X > 0.05 || move.Sticks[0].Y > 0.05 || move.Sticks[0].X < -0.05 || move.Sticks[0].Y < -0.05)

The problem is move = null. Am I setting up the input maps correctly? Also my next step is to have gamers select which player they are. Should I do that step first before I continue? Im also already going to try to make sure this controller logic is sound to pass the evil checklist.

Lastly, if it is alright with Henry I would like to post a small tutorial on how to set up 2 or more players with the Game kit.



#3
10/16/2010 (11:53 am)
Dude knock yourself out!

Its free for anyone to use change whatever.