Behavior bug?
by Eyaly · in Torque Game Builder · 07/24/2008 (3:38 am) · 2 replies
Hi
I'v test this Behavior on a single object and it works fine.
my problem arise when:
1. I copy object that have this Behavior
2. paste a new object ( on TGB editor )
so if i have object ( objA ) that have this Behavior
and i copy from objA then paste it ( objB )
some strange things happen to my objects.
objA will go to some unexpected direction and objB will
be in the correct path.
what im doing wrong here? or maybe its a bug?
thanks
if (!isObject(DynamicMotion))
{
%template = new BehaviorTemplate(DynamicMotion);
%template.friendlyName = "Dynamic Motion";
%template.behaviorType = "Movement";
%template.description = "Move on specific path";
%template.addBehaviorField(VecArray, "object vectors path x1 y1..xn yn(first vector shouldnt start at 0,0 value)", string, "56 -19 31 -13 9 4.5 -17 -8 -60 10");
%template.addBehaviorField(Speed,"movement speed",int,10 );
%template.addBehaviorField(ScaleFactor,"increase/decrease path size",float,1.0 );
// %template.addBehaviorField(offsetX,"offset x",float,0.0 );
// %template.addBehaviorField(offsetY,"offset y",float,0.0 );
}
function DynamicMotion::onBehaviorAdd( %this )
{
for ( %i = 0; %i < getWordCount(%this.VecArray); %i++ )
{
%word = getWord(%this.VecArray,%i);
%word *= %this.ScaleFactor;
%this.VecArray = setWord(%this.VecArray,%i,%word);
}
//prepare vector
%this.vecCount = getWordCount( %this.VecArray ) ;
%this.curIdx = 0;
%startX = getWord( %this.VecArray,0 );
%startY = getWord( %this.VecArray,1 );
//%this.owner.position = %startX+0.2 SPC %startY+0.2;
%this.evtMotion = %this.schedule(50,"moveOnPath");
}
function DynamicMotion::onBehaviorRemove(%this)
{
if( isEventPending( %this.evtMotion ) )
cancel( %this.evtMotion );
}
function DynamicMotion::moveOnPath( %this )
{
%nextVec = getWords( %this.VecArray,%this.curIdx,%this.curIdx+1 );
%this.curIdx+=2;
%this.owner.moveTo( %nextVec,%this.Speed,false,true,false, 0.01 );
}
function DynamicMotion::onPositionTarget(%this)
{
if( (%this.vecCount - %this.curIdx) >= 2 )
%this.evtMotion = %this.schedule(50,"moveOnPath");
}
I'v test this Behavior on a single object and it works fine.
my problem arise when:
1. I copy object that have this Behavior
2. paste a new object ( on TGB editor )
so if i have object ( objA ) that have this Behavior
and i copy from objA then paste it ( objB )
some strange things happen to my objects.
objA will go to some unexpected direction and objB will
be in the correct path.
what im doing wrong here? or maybe its a bug?
thanks
if (!isObject(DynamicMotion))
{
%template = new BehaviorTemplate(DynamicMotion);
%template.friendlyName = "Dynamic Motion";
%template.behaviorType = "Movement";
%template.description = "Move on specific path";
%template.addBehaviorField(VecArray, "object vectors path x1 y1..xn yn(first vector shouldnt start at 0,0 value)", string, "56 -19 31 -13 9 4.5 -17 -8 -60 10");
%template.addBehaviorField(Speed,"movement speed",int,10 );
%template.addBehaviorField(ScaleFactor,"increase/decrease path size",float,1.0 );
// %template.addBehaviorField(offsetX,"offset x",float,0.0 );
// %template.addBehaviorField(offsetY,"offset y",float,0.0 );
}
function DynamicMotion::onBehaviorAdd( %this )
{
for ( %i = 0; %i < getWordCount(%this.VecArray); %i++ )
{
%word = getWord(%this.VecArray,%i);
%word *= %this.ScaleFactor;
%this.VecArray = setWord(%this.VecArray,%i,%word);
}
//prepare vector
%this.vecCount = getWordCount( %this.VecArray ) ;
%this.curIdx = 0;
%startX = getWord( %this.VecArray,0 );
%startY = getWord( %this.VecArray,1 );
//%this.owner.position = %startX+0.2 SPC %startY+0.2;
%this.evtMotion = %this.schedule(50,"moveOnPath");
}
function DynamicMotion::onBehaviorRemove(%this)
{
if( isEventPending( %this.evtMotion ) )
cancel( %this.evtMotion );
}
function DynamicMotion::moveOnPath( %this )
{
%nextVec = getWords( %this.VecArray,%this.curIdx,%this.curIdx+1 );
%this.curIdx+=2;
%this.owner.moveTo( %nextVec,%this.Speed,false,true,false, 0.01 );
}
function DynamicMotion::onPositionTarget(%this)
{
if( (%this.vecCount - %this.curIdx) >= 2 )
%this.evtMotion = %this.schedule(50,"moveOnPath");
}
#2
This was the problem.
copy object and paste will copy also the object name.
maybe in the future release this way of copy paste should be change,
so copy action wont copy the object names.
thanks again James.
07/24/2008 (6:21 am)
Problem solvedThis was the problem.
copy object and paste will copy also the object name.
maybe in the future release this way of copy paste should be change,
so copy action wont copy the object names.
thanks again James.
Associate James Ford
Sickhead Games
Make sure your objects have different names.