Click Select and move
by Jimmy Chen · in Torque Game Builder · 11/06/2007 (9:26 am) · 1 replies
What is the cleaness way to design behaviors so that if I click on an object and then click on its destination anywhere on the screen, it will automatically move to that position? I was thinking of using combination of AI/Move Toward and RTS/MousePointer and MakeSelectable? How should I track the objects selected so I can cycle through it? And also queue up a list of destination point it needs to visit and exec callback?
So I started with this code. Where should I store a list of my destination points? In an global array? Create an scene object and store it there?
Also the problem with this approach is that the object listens to all mouse events including onClick of other objects. What can I do so that it only listens to onclick empty spaces on the screen? Is there a way to check which objects gets click on the top first?
-----
if (!isObject(MoveQueueBehavior))
{
%template = new BehaviorTemplate(MoveQueueBehavior);
%template.friendlyName = "Move Queue";
%template.behaviorType = "RTS";
%template.description = "Move to queue of Destination Points";
%template.addBehaviorField(speed, "The speed to move toward the object at (world units per second)", float, 10.0);
}
function MoveQueueBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function MoveQueueBehavior::onAddToScene(%this, %scenegraph)
{
%this.owner.setMouseLocked(true);
}
function MoveQueueBehavior::onMouseDown(%this, %modifier, %worldPos)
{
%this.owner.moveTo(%worldPos, %this.speed);
}
So I started with this code. Where should I store a list of my destination points? In an global array? Create an scene object and store it there?
Also the problem with this approach is that the object listens to all mouse events including onClick of other objects. What can I do so that it only listens to onclick empty spaces on the screen? Is there a way to check which objects gets click on the top first?
-----
if (!isObject(MoveQueueBehavior))
{
%template = new BehaviorTemplate(MoveQueueBehavior);
%template.friendlyName = "Move Queue";
%template.behaviorType = "RTS";
%template.description = "Move to queue of Destination Points";
%template.addBehaviorField(speed, "The speed to move toward the object at (world units per second)", float, 10.0);
}
function MoveQueueBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function MoveQueueBehavior::onAddToScene(%this, %scenegraph)
{
%this.owner.setMouseLocked(true);
}
function MoveQueueBehavior::onMouseDown(%this, %modifier, %worldPos)
{
%this.owner.moveTo(%worldPos, %this.speed);
}
Associate James Ford
Sickhead Games
When the mouse is clicked you need to first know was an object or a position clicked on. If it was an object, change the selected object; if it was a position and we have a selected object, then move it there. This can be done simply without behaviors at all.
You can still use behaviors for other things, but I wouldn't handle mouse clicks or keep track of selected satus inside it. If you have multiple objects selected and want to order them all to move, how do you know which ones to give the order to without looping through every unit? You need a global simset to hold currently selected objects.
However, queued destinations could be stored inside an object's behavior. When it is determined that the mouse was clicked while a unit was selected and the ctrl key was held (for example) you call a behavior method like EnqueWaypoint and then make the moveto call from within the behavior.