Game Development Community

Controlling Multiple Objects

by Kent Frauendienst · in Torque X 2D · 12/07/2009 (3:39 pm) · 4 replies

I have a game (a shoot-em-up) which will have the player controlling his ship while also shooting weapons that are mounted to it as separate objects. This is posing a problem, because I can apparently only have my inputMap directly control (through bindMove) the object that's designated as the Player object, which is the ship itself, but I also need to be able to affect the mounted object (the weapon) as well. I've been wracking my brain, trying to figure this out, but I feel like I'm just missing something.

Simply put, I need to be able to have one player control multiple objects at once.

I'm trying to make this work in a way where things are modular, since that's one of the key designs behind the game. That is, the ship triggers the weapon which fires the projectile, rather than the ship itself firing the projectile, and the weapon is whatever object that I mount to the "MainWeapon" link point on the ship (which will always have a component that makes it shoot). Perhaps there's a way to expose the "move" from the Player object's ProcessTick method or a means of having multiple objects make binds on the same inputMap?

Any input is appreciated.

#1
12/08/2009 (1:15 pm)
Hi Kent,

I'm not sure to get your problem. When you mount the object you have it there, so you can reference it in the player itself (the ship?) as _currentWeapon or something like that... you really don't need to have more than one InputMap and that it's properly assigned to the player.

Does this make sense to you?
#2
12/09/2009 (11:21 am)
Thanks for the response.

Yeah, I'm currently trying to get the component I'm using to hold a variable with the object's name, that's pulled from the player object using obj.LinkPoints.GetMountedObject("LinkPointName"). At least, this should work. The problem comes in when I'm trying to use the target object's ProcessTick method as a means of executing the game logic for creating and firing the projectile, like in the Blaster tutorial.

Since it will eventually be possible for the player to be firing several weapons at once in this way, I wanted to utilize the ProcessTick method (since it already is happening all the time), rather than triggering a new method all the time, for the sake of efficiency.

...But I guess I don't really need to be worrying about efficiency too terribly much, if I just have the player object's ProcessTick tell the weapon object to run a "fire" method when the proper input is detected, that should work out just fine. I'll give it a shot.
#3
12/09/2009 (1:37 pm)
As it turns out, that worked just perfectly.

Here's the working bit of it, inside the ProcessTick method of the component on which the InputMap is defined, on the player object:

// We have to call a method from the ShootsMainComponent of a different object.
// Find and define it first.
_mainWeaponObject = _sceneObject.GetMountedObject("MainWeapon");
ShootsMainComponent SMC = _mainWeaponObject.Components.FindComponent<ShootsMainComponent>();
SMC.FireWeapon(move, dt); // Simple method call.

Progress! Things actually work now; The player's ship controls its mounted objects just fine now. Thanks for the input!
#4
12/09/2009 (8:22 pm)
Hi,

I'm glad that you sorted it out using this way which is actually the best I can think about ;)