Get stuck in AiPlayer's onMoveStuck() method :(
by Christin Stock · in Torque Game Engine · 07/19/2009 (7:15 pm) · 3 replies
hi,I have modified the aiPlayer.cpp to fire an "onMoveStuck()" callback, as follows, and the mStuckTolerance is set to 0.01f.
// We should check to see if we are stuck...
//if (location == mLastLocation) {
// throwCallback("onMoveStuck");
// mMoveState = ModeStop;
//}
//new callback for onMoveStuck
F32 xDiffLast = mFabs(mLastLocation.x - location.x);
F32 yDiffLast = mFabs(mLastLocation.y - location.y);
F32 zDiffLast = mFabs(mLastLocation.z - location.z);
if ( xDiffLast< mStuckTolerance && yDiffLast < mStuckTolerance && zDiffLast < mStuckTolerance)
{
mMoveState = ModeStuck;
throwCallback("onMoveStuck");
}
else
{
mLastLocation = location;
}
it does work well! but what really bothers me is how to help the ai get out of stuck. I thought it was easy, define 8 movement offside directions in an array and try to setMoveDestination() of each offside direction in turn, so I wrote my onMoveStuck() (a datablock method) in aiplayer.cs file like this:
$stuckOffsideRadius = 10 ;
$cardinalDirection[0] = "0" SPC $stuckOffsideRadius SPC "0"; // N
$cardinalDirection[1] = $stuckOffsideRadius SPC $stuckOffsideRadius SPC "0"; // NE
$cardinalDirection[2] = $stuckOffsideRadius SPC "0" SPC "0"; // E
$cardinalDirection[3] = $stuckOffsideRadius SPC -$stuckOffsideRadius SPC "0"; // SE
$cardinalDirection[4] = "0" SPC -$stuckOffsideRadius SPC "0"; // S
$cardinalDirection[5] = -$stuckOffsideRadius SPC -$stuckOffsideRadius SPC "0";// SW
$cardinalDirection[6] = -$stuckOffsideRadius SPC "0" SPC "0"; // W
$cardinalDirection[7] = -$stuckOffsideRadius SPC $stuckOffsideRadius SPC "0"; // NW
$NUM_CARDINALS = 8;
...
function DemoPlayer::onMoveStuck(%this)
{
if( %this.stuckTurningDirection $="" )
{
%this.stuckTurningDirection = 0;
}
if( %this.stuckTurningDirection >=8 )
{
%this.stuckTurningDirection = 0;
}
%newpos = vectoradd(%this.getPosition(),$cardinalDirection[%this.stuckTurningDirection]);
%this.SetMoveDestination(%newpos,false);
%this.stuckTurningDirection++;
}
in most cases, when my ai gets in stuck, it just turns its face to a offsie direction in turn but without a move! I think it maybe still stuck in the same place. Is there anything relate to the processtick() defined in player.cpp? in a tick timespan, the ai cannot have a movement offside bigger than mStuckTolerance, so it still in stuck??
I am not sure. do you have any ideas?
// We should check to see if we are stuck...
//if (location == mLastLocation) {
// throwCallback("onMoveStuck");
// mMoveState = ModeStop;
//}
//new callback for onMoveStuck
F32 xDiffLast = mFabs(mLastLocation.x - location.x);
F32 yDiffLast = mFabs(mLastLocation.y - location.y);
F32 zDiffLast = mFabs(mLastLocation.z - location.z);
if ( xDiffLast< mStuckTolerance && yDiffLast < mStuckTolerance && zDiffLast < mStuckTolerance)
{
mMoveState = ModeStuck;
throwCallback("onMoveStuck");
}
else
{
mLastLocation = location;
}
it does work well! but what really bothers me is how to help the ai get out of stuck. I thought it was easy, define 8 movement offside directions in an array and try to setMoveDestination() of each offside direction in turn, so I wrote my onMoveStuck() (a datablock method) in aiplayer.cs file like this:
$stuckOffsideRadius = 10 ;
$cardinalDirection[0] = "0" SPC $stuckOffsideRadius SPC "0"; // N
$cardinalDirection[1] = $stuckOffsideRadius SPC $stuckOffsideRadius SPC "0"; // NE
$cardinalDirection[2] = $stuckOffsideRadius SPC "0" SPC "0"; // E
$cardinalDirection[3] = $stuckOffsideRadius SPC -$stuckOffsideRadius SPC "0"; // SE
$cardinalDirection[4] = "0" SPC -$stuckOffsideRadius SPC "0"; // S
$cardinalDirection[5] = -$stuckOffsideRadius SPC -$stuckOffsideRadius SPC "0";// SW
$cardinalDirection[6] = -$stuckOffsideRadius SPC "0" SPC "0"; // W
$cardinalDirection[7] = -$stuckOffsideRadius SPC $stuckOffsideRadius SPC "0"; // NW
$NUM_CARDINALS = 8;
...
function DemoPlayer::onMoveStuck(%this)
{
if( %this.stuckTurningDirection $="" )
{
%this.stuckTurningDirection = 0;
}
if( %this.stuckTurningDirection >=8 )
{
%this.stuckTurningDirection = 0;
}
%newpos = vectoradd(%this.getPosition(),$cardinalDirection[%this.stuckTurningDirection]);
%this.SetMoveDestination(%newpos,false);
%this.stuckTurningDirection++;
}
in most cases, when my ai gets in stuck, it just turns its face to a offsie direction in turn but without a move! I think it maybe still stuck in the same place. Is there anything relate to the processtick() defined in player.cpp? in a tick timespan, the ai cannot have a movement offside bigger than mStuckTolerance, so it still in stuck??
I am not sure. do you have any ideas?
#2
Finally I find it is a bug in my ai task schedule method which results in the above ai's weird behaviour. I will give a shoot of your suggestion.
07/19/2009 (9:52 pm)
thanks bryce! Finally I find it is a bug in my ai task schedule method which results in the above ai's weird behaviour. I will give a shoot of your suggestion.
#3
07/20/2009 (5:21 am)
I recommend raising the value of minImpactSpeed in the AI Player's datablock if you use my system...it's been known to injure them depending on where they are.
Torque Owner Bryce
Toy Story 2 was O.K.
%speed = 700; %vector = getRandom(-1,1) SPC getRandom(-1,1) SPC "0"; %pushVector = VectorScale(%vector,%speed); // The vector we should push ourselves in order to get free %player.applyImpulse(%plr.getPosition(),%pushVector);It "nudges" the player in a random direction to get un-stuck