Game Development Community

Multiple Player objects

by Ross Kelly · in Torque X 2D · 02/27/2009 (11:52 am) · 6 replies

Is their a way of creating multiple player objects, all assigned to the movementcomponent of player1, without having to mount the objects to one another.

The problem that I m having is that, I add my first player object and add a movecomponent with the player input set to 0. Then When I add a second player object and assign it a movementcomponent also set to 0, it overrides the first one, and only the second object moves.

Is there a way of getting both objects to move from player 1 inputs, without mounting them to each other?

#1
02/27/2009 (3:00 pm)
How are you creating the MoveComponent?

All my controller and player objects are created inside a loop so each player gets a new MoveComponent. Assuming you have a similar setup, I think what's happening is that each time you create a new MoveComponent for index 0 it overrides the previous one. My first thought in this situation to try creating a single MoveComponent and assigning this same component to all players.
#2
02/28/2009 (1:11 am)
I am adding the MoveComponent in the 2D builder to each object, both assigned an index of 0.

I'm wanting one object to be controlled by my left thumb stick, and the other object to be moved by the right thumb stick, both on index 0 gamepad. But only the second object is getting controls.

So I think the MoveComponent is overriding the previous one. Any idea's to get around that?

Or would I have to program my own CustomMoveComponent?
#3
02/28/2009 (9:33 am)
I had a similar problem when I started spawning multiple player objects in my game. I have a PlayerController that controls movement with the left stick and a separate AimingComponent that controls player aiming with the right stick. The way I had things setup caused the PlayerController part to work just fine but the AimingComponent would only work on the last spawned player. This was happening because I wasn't creating a new AimingComponent for each player, but reusing the same one.

Anyway, this wasn't the behavior I wanted but it does sound similar to what you want. In my situation the PlayerController defined how the player should respond the left stick and the AimingComponent defined how the player should response to the right stick. There was no overlap, i.e., AimingComponent didn't set anything for the left stick and vice versa.

So perhaps having something like a LeftMoveComponent that sets up the left stick and a RightMoveComponent right move component that sets up the right stick may work out for you. This way you can setup both sticks on the same player index without any conflicts between the MoveComponents.
#4
03/02/2009 (11:22 am)
Thanks Sean

Worked it out in the end. U pointed me in the right direction.
#5
03/02/2009 (11:23 am)
Sweet! Might I ask what you did?
#6
03/02/2009 (11:48 am)

Ok, I will try to explain it best I can, hope you can follow.

First I created a CustomMovementComponent, the exact same as the auto generated MovementComponent, only difference is that it excepts two T2DSceneObjects properties inputs.

I then placed an invisible T2DSceneobject outside of the camera's point of view in the TX2D builder. And placed the two objects that I want to control into position.

I then added the customMovementComponent to the invisible object off screen. So this invisible object would be representing my player1. Set its index to 0, and its two T2DSceneobjects assigned to each of my objects that I want to move.

It was just a matter that of binding the keys to the different thumbpads, with different move indexes.


int gamepadId = InputManager.Instance.FindDevice(gamePad);
            if (gamepadId >= 0)
            {
                inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftThumbX, 
MoveMapTypes.StickAnalogHorizontal, 0);
                inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.LeftThumbY, 
MoveMapTypes.StickAnalogVertical, 0);

                inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightThumbX, 
MoveMapTypes.StickAnalogHorizontal, 1);
                inputMap.BindMove(gamepadId, (int)XGamePadDevice.GamePadObjects.RightThumbY, 
MoveMapTypes.StickAnalogVertical, 1);

                inputMap.BindAction(gamepadId, (int)XGamePadDevice.GamePadObjects.Back,
 _OnBackButton);
            }

Then Just add the .Physics.Velocity to each of the objects different move indexes.

_objectMovementControl1.Physics.VelocityX = move.Sticks[0].X * 20.0f;
                _objectMovementControl2.Physics.VelocityX = move.Sticks[1].X * 20.0f;

Hope that makes sense