Game Development Community

Is this possible?

by Paul Bellezza · in Torque X 2D · 10/23/2007 (12:15 am) · 3 replies

I've created an AI helper for my player character to use, I want the player to be able to spawn the AI helper on a button press. I've already written the code for the AI helper but is it possible to make the helper spawn without doing anything in Torque Builder? I know I can create a new instance of a component, but how would I assign it the appropriate controller as well?

#1
10/23/2007 (1:52 pm)
Hrm, going by the TorqueCombat demo it seems possible but its kind of a headache so far. I wish there was a simpler example of this.
#2
10/23/2007 (10:02 pm)
Here's a similar thread now running, relating to AI spawning.
www.garagegames.com/mg/forums/result.thread.php?qt=68563

If I understand your question right, I think the solution is even easier than you think. I'm guessing that your AI's component performs its work within the ProcessTick() method. If so, then just keep the component attached to the AI unit but DO NOT call the AddTickCallback() method within the _OnRegister() method. Instead, add an entirely new method called StartWorking().

public void StartWorking()
{
     ProcessList.Instance.AddTickCallback(Owner, this);
     return;
}

If the AI ain't tick'n, then he's probably not work'n. If you start requesting ticks in a separate method like this, you essentially control the component's heartbeat. You can create the AI and it will just sit there until you call the StartWorking() method to start doing something. Hope that helps.

John K.
#3
11/01/2007 (5:12 pm)
John, Paul and I are on the same project team so that's why the similar thread. The problem has been resolved. I made the changes I needed to the OnRegister so as to add the correct AIController.

Thanks though!