Behavior and moveTo
by eqdarkleaf · in Torque Game Builder · 03/19/2009 (2:01 pm) · 2 replies
Hey guys, this is my first post so be gentle. I have been working on a particular issue for a while combining a cloned object with a moveTo function.
It seems that when you clone an object, whatever state it is currently in (ie. already moving to object), all cloned objects inherit this attribute, even if the reference object is disabled (behavior template).
To get around this problem, I have implemented schedules to loop certain sections to re-evaluate the moveTo position, and in some circumstances this has worked, if the moveTo position is static. However, if the moveTo position is dynamic (getRandom), it does not seem to work.
To work around that issue, I made a simple if statement. If object is disabled (reference object is), the script loops. If it is not (cloned objects aren't) then it evaluates the moveTo position. However this does not appear to work, it acts as in the original problem, where the cloned objects inherit the moveTo position of the reference object, and the cloned objects never meet that position, which leads me to believe that the reference object is still passing information even though it is disabled.
This is an AI script assigned to the reference object, a spawn area creates the clones (spwanArea behavior). If I remove the spawn area and template behavior from the reference object, the script works as intended (however only for that 1 object, no clones :( )
Any Ideas, thoughts, ect?
In case I wasnt entirely clear up there, the onPositionTarget code never runs, the objects keep moving in the same direction, but behavior works when object is not a clone.
It seems that when you clone an object, whatever state it is currently in (ie. already moving to object), all cloned objects inherit this attribute, even if the reference object is disabled (behavior template).
To get around this problem, I have implemented schedules to loop certain sections to re-evaluate the moveTo position, and in some circumstances this has worked, if the moveTo position is static. However, if the moveTo position is dynamic (getRandom), it does not seem to work.
To work around that issue, I made a simple if statement. If object is disabled (reference object is), the script loops. If it is not (cloned objects aren't) then it evaluates the moveTo position. However this does not appear to work, it acts as in the original problem, where the cloned objects inherit the moveTo position of the reference object, and the cloned objects never meet that position, which leads me to believe that the reference object is still passing information even though it is disabled.
This is an AI script assigned to the reference object, a spawn area creates the clones (spwanArea behavior). If I remove the spawn area and template behavior from the reference object, the script works as intended (however only for that 1 object, no clones :( )
Any Ideas, thoughts, ect?
function powerShip::onAddToScene(%this, %scenegraph)
{
%this.setupShip();
}
function powerShip::setupShip(%this)
{
if(%this.owner.enabled) //%this.owner.getEnabled(); causes errorin log, Unknown Command getEnabled()
{
%this.gototarget();
}
if(%this.owner.counter == 0)
{
%this.schedule( 150, "setupShip");
}
}
function powerShip::gototarget(%this)
{
%orignY = %this.owner.getPositionY();
%valueX = getRandom( %this.minX , %this.maxX);
%valueY = getRandom(%this.minY , %this.maxY );
%this.owner.setPosition(%valueX, %orignY);
%this.owner.moveTo(%valueX, %valueY, %this.speed, false, true);
%this.owner.counter++;
}
function powerShip::onPositionTarget(%this)
{
rest of code...In case I wasnt entirely clear up there, the onPositionTarget code never runs, the objects keep moving in the same direction, but behavior works when object is not a clone.
About the author
#2
03/19/2009 (6:15 pm)
oh also why do you need the maxy and maxx ? set a point to the middle of your sprite and just setposition
Torque Owner michael bailey