Game Development Community

Getting AI to react to touch

by DreamPharaoh · in Technical Issues · 03/07/2008 (12:24 pm) · 3 replies

I have been using Mark's resource for AIguard. It has really helped my progression, but I am trying to get the bots to recognize when they are touched by a client. If I sneak up behind a bot and push into it, it just sits there until I am in front of it. I have tried numerous variations of the code below. I appreciate any help.



function AIPlayer::OnCollison(%this, %obj, %col, %tgt)
{
VectorSub(%tgt.player.getPosition(), %obj.getPosition());
if(%col.getClassName() $= %tgt)

{
echo("Ahh Haa!");

%obj.fov = 360;
%this.fovtrigger = %this.schedule($AI_PLAYER_ENHANCED_FOV_TIME,"restorefov", %obj);
}
}
//RestoreFOV - this function resets the AIPlayer's FOV back to the default value for the bot
function AIPlayer::restoreFOV(%this, %obj)
{
%obj.fov = $AI_PLAYER_FOV;
}

#1
03/07/2008 (4:17 pm)
Try something like this
function AIPlayer::onCollision(%this, %obj, %col)
{
    if(%col.getDatablock().getName() $= "PlayerBody")
    { 
        echo("Found a target, lets attack");
        %obj.enhanceFov(%obj);
    }
    else
    {
        echo("Collided with something else");
    }
}

function AIPlayer::EnhanceFOV(%this, %obj)
{
	if (%obj.fov != 360)
	{
		%obj.fov = 360;
		%this.fovtrigger = %this.schedule($AI_PLAYER_ENHANCED_FOV_TIME,"restorefov", %obj);
	}
}
#2
03/07/2008 (5:50 pm)
This doesn't work either. It doesn't even call an echo when toaching the back of an AI.
#3
03/07/2008 (6:20 pm)
You need to use the datablock not the class. In stock TGE Eg.

function DemoPlayer::onCollision(%this,%obj,%col)
{
   if (%obj.getState() $= "Dead")
      return;

   // Try and pickup all items
   if (%col.getClassName() $= "Item")
      %obj.pickup(%col);

   // Mount vehicles
   %this = %col.getDataBlock();
   if ((%this.className $= WheeledVehicleData) && %obj.mountVehicle &&
         %obj.getState() $= "Move" && %col.mountable) {

      // Only mount drivers for now.
      %node = 0;
      %col.mountObject(%obj,%node);
      %obj.mVehicle = %col;
   }

   // if touched by player turn around and own him!     
}