Controlling movement without the PlayerManager
by Evan McIlvride · in Torque X 2D · 10/01/2007 (7:08 pm) · 4 replies
I'm working on a game where I need to be able to move one thumbstick to control a player and another thumbstick to control that player's cursor. Since I can only assign controls to one of these objects using the player manager, I'm guessing that I manually need to use InputMaps and MoveManagers. The documentation says that in order to do this I need to:
1. Create an input map with a number of move binds.
2. Bind some move manager to the input map (inputMap.MoveManager = moveManager).
3. Configure a move manager to handle moves how you want them (e.g., ConfigureStickHorizontalScaling and ConfigureStickHorizontalTracking as shown above).
4. Associate a game object with a move manager (moveManager.Consumer = player).
I can do the first three, but the moveManager object does not have a Consumer field. I'm assuming that it doesn't work because I'm not assigning a Consumer to the move manager, but I can't find a way to do it. Is there something I'm missing here, or should I be implementing this in an entirely different way?
Thanks.
1. Create an input map with a number of move binds.
2. Bind some move manager to the input map (inputMap.MoveManager = moveManager).
3. Configure a move manager to handle moves how you want them (e.g., ConfigureStickHorizontalScaling and ConfigureStickHorizontalTracking as shown above).
4. Associate a game object with a move manager (moveManager.Consumer = player).
I can do the first three, but the moveManager object does not have a Consumer field. I'm assuming that it doesn't work because I'm not assigning a Consumer to the move manager, but I can't find a way to do it. Is there something I'm missing here, or should I be implementing this in an entirely different way?
Thanks.
About the author
Recent Threads
#2
10/03/2007 (8:02 pm)
That worked great John! Thanks a lot for your help :)
#3
08/31/2010 (9:52 am)
How would you go about making the player rotate with the target object? My player object is a sprite with a gun in hand and would like to have the gun be pointing at the target object for aiming. Thanks.
#4
After reading your question again, this is probably not the solution your looking for. I will post again if I figure it out :-)
08/31/2010 (5:39 pm)
This will setup rotation via the right thumb stick_sceneObject.Physics.AngularVelocity = move.Sticks[1].X * 20.0f;
After reading your question again, this is probably not the solution your looking for. I will post again if I figure it out :-)
Associate John Kanalakis
EnvyGames
If your project is based on the Torque X StarterGame project, then you should still have the MovementComponent.cs file. That's a good place to make the change.
Add the following private field to the MovementComponent:
Next, add some public properties to expose this object:
public T2DSceneObject TargetObject { get { return _target; } set { _target = value; } }Next, change the _SetupInputMap to look like this:
private void _SetupInputMap2(TorqueObject player, int playerIndex, String gamePad, String keyboard) { // Set player as the controllable object PlayerManager.Instance.GetPlayer(playerIndex).ControlObject = player; // Get input map for this player and configure it InputMap inputMap = PlayerManager.Instance.GetPlayer(playerIndex).InputMap; 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); } }Next, Change the ProcessTick() method to look like this:
public void ProcessTick(Move move, float elapsed) { if (move != null) { _sceneObject.Physics.VelocityX = move.Sticks[0].X * 20.0f; _sceneObject.Physics.VelocityY = -move.Sticks[0].Y * 20.0f; _target.Physics.VelocityX = move.Sticks[1].X * 20.0f; _target.Physics.VelocityY = -move.Sticks[1].Y * 20.0f; } }That's it for the code. Now rebuild the project and open Torque X Builder.
Drag your target/crosshairs object into the scene.
Go to the Edit tab & Scripting rollout and enter the name "target" into the Name field.
Then select your player object (which should have the MovementComponent attached).
Select the Edit tab & Components rollout.
Under the MovementComponent, there should be a new field called TargetObject.
In that list you should be able to select "target" that references your target/crosshairs object.
That's it. Now save everything and run. If all goes well, the left thumbstick should move the player around and the right thumbstick should move the crosshairs around. And the best part of this approach is that the MovementComponent has a quick reference to the player object and the target object, so it's quick and easy to get an angle between the two as your direction of weapons fire.
John K.