A moveTo() function question
by Gustavo Boni · in Torque Game Builder · 12/14/2006 (1:00 pm) · 4 replies
Hey guys,
In my game, i use moveTo functions for enemies AI. If the players collides with an enemy while this enemy is moving to (using moveTo function) it gets crazy moving slowly an with no definide direction.
How can i handle this?
I mean, when the player hit the object which is moving to, how can i say to this object stop or back to the initial position?
Thanks
In my game, i use moveTo functions for enemies AI. If the players collides with an enemy while this enemy is moving to (using moveTo function) it gets crazy moving slowly an with no definide direction.
How can i handle this?
I mean, when the player hit the object which is moving to, how can i say to this object stop or back to the initial position?
Thanks
#2
12/15/2006 (7:37 am)
In the onCollision function for the player or object you could call a function which will make the enemy do what every you wanted it to do...example from the player' on collision function:function playerClass::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal,
%contactCount, %contacts )
{
if(%this.isDead)
return;
if(%dstObj.class $= "myBadGuyClass")
{
%dstObj.myFunction();
%srcObj.myHeroDead();
}
}
#3
What i need to do is when the object is moving for a position, if it collides something in the way before reching the destination, it should choose randomly another position to go.
12/15/2006 (7:51 am)
Thanks Jon, but the problem is when my object is going to a position (called moveTo() function), if it collides with other object it will not stop or do other action.What i need to do is when the object is moving for a position, if it collides something in the way before reching the destination, it should choose randomly another position to go.
#4
Just remember to turn of the flags in the correct spots.
12/15/2006 (8:56 am)
I have the same thing with my AI...I flag it with a variable say %this.wasHit = true; then and use it like this:function badGuyClass::AI01(%this)
{
if(!%this.wasHit)
{
%this.moveTo(0, 0, 30, true, true);
}
}
function badGuyClass::myFunction(%this)
{
create move to random function
}Just remember to turn of the flags in the correct spots.
Torque Owner Gustavo Boni