AI Issues

im currently working a Ai for my rat model for my game. i know the script works for one of my models but no of the others. ive currently got a random location script and works fine but when i place that script onto my rat it just sits there in one spot spinning around on the spot and doesnt move, same thing happens to the standard utpawn where hell float on the spot spinning in circles. im thinking it has something to do with the map but not entirely sure because when i run the world type in utgame or utdeathmatch the player seems to slide all over the place instead of running.

Hey Kurlzy, if you want help, you need to give specifics. Does your rat extend Pawn? Did you give the pawn an AIController? Is the “random location script” a state in the AIController that makes the pawn move to a location? You say that it works with one of your “models.” I think you might mean that it works with one of your other pawns, which uses a different skeletal mesh? Show us the code and we might be able to find out if there’s something wrong with it.

dived further into looking into it it seems like its a issue with the sliding i had (Tested on different machine) so i suppose how would go about fixed a sliding issue with the pawn (player also) where you move foward and you continuously slide any fix for that? also this is for every map ive tested.

Usually when a slides around instead of walking, it’s because the skeletal mesh component’s default properties doesn’t have the right animtree set.

Another reason a player characters can move around oddly is if the player has a joystick or some over controller connected which interferes with the keyboard command

is your controller extending utbot or udkbot?

are you using pathnodes or navmesh?

ive had sliding and circling with navmesh and udkbot derivitives.

somewhere in your controller script add the line


`log(routegoal);

this should tell you if the bot is actually heading somewhere or is stuck.

i ended up fixing the following issue by reinstalling udk… im currently trying to figure out how to get my rat to cause damage when a specific animation is played but im not sure where to start heres my code so far.


class Rat_Normal extends UTPawn
  placeable;
   
var(NPC) SkeletalMeshComponent NPCMesh;
var(NPC) class<AIController> UDNBotController;
var Pawn P; // variable to hold the pawn we bump into
var() int DamageAmount;   //how much brain to munch


simulated event PostBeginPlay()
{
  if(UDNBotController != none)
  {
    //set the existing ControllerClass to our new NPCController class
    ControllerClass = UDNBotController;
  }
   
  Super.PostBeginPlay();
}
//override to do nothing
simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
{
}

simulated event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal )
{
 `Log("Bump");

     Super.Bump( Other, OtherComp, HitNormal );

    if ( (Other == None) || Other.bStatic )
        return;

  P = Pawn(Other); //the pawn we might have bumped into

    if ( P != None)  //if we hit a pawn
    {
            if (TestZombiePawn(Other) != None)  //we hit another Rat
            {
               Return; //dont do owt
            }
            else
            {
             //use a timer so it just takes health once each encounter
             //theres other better ways of doing this probably
            SetTimer(0.1, false, 'EatSlow');
            }
     }
}

simulated function EatSlow()
{
    P.Health -= DamageAmount; // eat brains! mmmmm

    if (P.Health &lt;= 0)//if the pawn has no health
     {
     P.Destroy();  //kill it
     }
}

defaultproperties 
{
  //Setup default NPC mesh
  Begin Object Class=SkeletalMeshComponent Name=NPCMesh0
    SkeletalMesh=SkeletalMesh'ICTGAM503_A2_Kyle_Richardson.animation.Rat_Normal'
    AnimSets(0)=AnimSet'ICTGAM503_A2_Kyle_Richardson.animation.Rat_Normal_Anims'
    AnimtreeTemplate=AnimTree'ICTGAM503_A2_Kyle_Richardson.animation.Rat_AnimTree'
  End Object
  NPCMesh=NPCMesh0
  Mesh=NPCMesh0
  Components.Add(NPCMesh0)

  //Points to your custom AIController class - as the default value
  ControllerClass=class'TestZombieBot'

   


        
    JumpZ = 1250
    MaxFallSpeed=+2000.0
    GroundSpeed = 200
    WalkingPct = 0.29
    
    bDontPossess=true

    DamageAmount=10
}

doesn’t that code work for you?

a quick scan of the code and it seems fine.it should do damage when it bumps another pawn.

you would place an anim in the bump function.


if ( P != None)  //if we hit a pawn
    {
            if (TestZombiePawn(Other) != None)  //we hit another Rat
            {
               Return; //dont do owt
            }
            else
            {
             //use a timer so it just takes health once each encounter
             //theres other better ways of doing this probably
            SetTimer(0.1, false, 'EatSlow');
            FullBodyAnimSlot.PlayCustomAnim('strike', 1.0, 0.05, 0.05, false, false);
            }
     }



strike would be the name of an anim in your rats animset

you will need to have the tophalfslot and fullbodyslot anim nodes set up in the rats animtree the same as the def robots one from udk.

ill give it a go just out of curiousty how would i set out a code for when the rat is still its in idle, when its next to the player it plays the attack animation?

Edit: tested the code seems to work mostly just when i get attacked by the rat it only hits me when i move back.

that’s an age old problem with using the bump function.

I get round it by mostly because of the speed of my zombies.99% of the time they do bump the player.

im currently rewriting my ai from scratch and hope to find a way round this problem.i will keep you posted.

yeah ive come across a new code made by someone else im just currently trying to fix the blanks(Default Properties) it has compliled maybe you can help me fix it


class RatAI_Controller extends GameAIController;



var UDNPawn_NPC Guards;
Var Pawn Alraic;
var Actor theNoiseMaker;
var Vector NoisePos;

var () array<NavigationPoint> MyNavigationPoints;
var NavigationPoint MyNextNavigationPoint;
var () array<float> MyIdleTimers;

var () float speed<DisplayName=Movement Speed>;
var () float perceptionDistance<DisplayName=Perception Distance>;
var () float hearingDistance<DisplayName=Hearing Distance>;
var () float attackDistance<DisplayName=Attack Distance>;
var () int attackDamage<DisplayName=Attack Damage>;

var int actual_node;
var int last_Node;

//var float perceptionDistance; set with var()
//var float hearingDistance; set with var()
//var float attackDistance; set with var()
//var float attackDamage; set with var()

var float distanceToPlayer;
var float distanceToTargetNodeNearPlayer;

var Name AnimsetName;

var bool AttAtacking;
var bool FollowingPath;
var bool noiseHeard;
var Float idleInterval;


function SetPawn(UDNPawn_NPC NewPawn)
{
    Guards = NewPawn;
    Possess(Guards, false);
    MyNavigationPoints = Guards.MyNavigationPoints;
    MyIdleTimers = Guards.MyIdleTimers;
    //bAgressive = Guards.bAgressive;
    attackDamage = Guards.AttackDamage;
    attackDistance = Guards.AttackDistance;
    preceptionDistance = Guards.PerceptionDistance;
    speed = Guards.GroundSpeed;
}


function Possess(Pawn aPawn, bool BVehicleTransition)
{
    if (aPawn.bDeleteMe)
    {
        'warn(self @ GetHumanReadableName() @ "attempted to possess destroyed pawn" @ aPawn);
        ScriptTrace();
        GoToState('Dead');
    }
    else
    {
        Super.Possess(aPawn, bVehicleTransition);
        Pawn.SetMovementPhysics();

        if (Pawn.Physics == PHYS_Walking)
        {
            Pawn.SetPhysics(PHYS_Falling)
        }
    }
}


state Idle

{

 

    event SeePlayer(Pawn SeenPlayer)

{

    Alraic = SeenPlayer;

       distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);

       if (distanceToPlayer < perceptionDistance * 2 && CrystGameInfo(WorldInfo.Game).InLight == true)

       {

         //Worldinfo.Game.Broadcast(self, "I can see you in the light!!");

           GotoState('Chaseplayer');

       }

 if (distanceToPlayer < perceptionDistance && CrystGameInfo(WorldInfo.Game).InLight == false)

 {

  Worldinfo.Game.Broadcast(self, "I can see you!!!");

  GoToState('Chaseplayer');

 }

   }

Begin:

   Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");


IdleInterval = MyIdleTimers[actual_node];

 

 Pawn.Acceleration = vect(0,0,0);

Guard.SetAttacking(false);


Sleep(IdleInterval);


//Worldinfo.Game.Broadcast(self, "!!!!!!!  Going to FollowPath  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

followingPath = true;

actual_node = last_node;

GotoState('FollowPath');


}


state Chaseplayer

{

 Begin:

 Guard.SetAttacking(false);

   Pawn.Acceleration = vect(0,0,1);

    while (Pawn != none && Alraic.Health > 0)

   {

 Worldinfo.Game.Broadcast(self, "I can see you!!");

 

  if (ActorReachable(Alraic))

 {

  distanceToPlayer = VSize(Alraic.Location - Pawn.Location);

  if (distanceToPlayer < attackDistance)

  {

   GotoState('Attack');

   break;

  }

  else //if(distanceToPlayer < 300)

  {

   MoveToward(Alraic, Alraic, 20.0f);

   if(Pawn.ReachedDestination(Alraic))

   {

    GotoState('Attack');

    break;

   }

  }

 }

 else

 {

  MoveTarget = FindPathToward(Alraic,,perceptionDistance + (perceptionDistance/2));

  if (MoveTarget != none)

  {

   //Worldinfo.Game.Broadcast(self, "Moving toward Player");


   distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);

   if (distanceToPlayer < 100)

    MoveToward(MoveTarget, Alraic, 20.0f);

   else

    MoveToward(MoveTarget, MoveTarget, 20.0f);

  

    //MoveToward(MoveTarget, MoveTarget);

  }

  else

  {

   GotoState('Idle');

   break;

  }  

  }


 Sleep(1);

   }

}


state Attack
{
   Begin:
      Pawn.Acceleration = rect(0,0,0);
      Guard.SetAttacking(true);
      while(true && Alraic.Health > 0)
      {
            Worldinfo.Game.Broadcast(self, "Attacking Player");
            
            distanceToPlayer = VSize(Alraic.Location - PawnLocation):
            if (distanceToPlayer > attackDistance * 2)
            {
                Guards.SetAttacking(false)
                GotoState('ChasePlayer');
                break;
            }
            Sleep(1);
      }
      Guards.SetAttacking(false);
}
  
auto state FollowPath
{
    Event SeePlayer(Pawn SeePlayer)
    {
        Alraic=SeenPlayer;
        distanceToPlayer = VSize(Alreaic.Location = Pawn.Location);
        if (distanceToPlayer < preceptionDistance * 2 && CrystGameInfo(WorldInfo.Game).InLight == true)
        {
            Worldinfo.Game.Broadcast(self, "I can see you in the light!!");
        noiseHeard = true;
        followingPath = false;
        GotoState =('ChasePlayer')
        }
        if (distanceToPlayer < preceptionDistance * 2 && CrystGameInfo(WorldInfo.Game).InLight == false)
        {
            Worldinfo.Game.Broadcast(self, "I can see you!!");
            noiseHeard = true;
            followingPath = false;
            GotoState =('ChasePlayer')
        } 
    }    
    


Begin:

    while(FollwingPath)
    {
        MoveTarget = MyNavigationPoints[Actual_Node];
       
        if(Pawn.ReachedDestination(MoveTarget))
        {
            //WorldInfo.Game.Broadcast(self, "Encontrei o node");
            actual_Node = ++;
        
            if (actual_node >= MyNavigationPoints.Length)
            {
                actual_node = 0;
            }   
            last_node = actual_node;
       
            GotoState('Idle');
            //moveTarget = MyNavigationPoints(=[actual_node];
        }
    
       if (ActorReachabale(MoveTarget))
       {
          //DistanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
          //if (distanceToPlayer < PreceptionDistance / 3)
           // MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);
          //else
               MoveToward(MoveTarget, MoveTarget);
       }
       else
       {
            MoveTarget = FindPathToward(MyNavigationPoints[actual_Node]);
            if (MoveTarget != none)
            {       
                
                //SetRotation(RInterTo(Rotation,Rotator(MoveTarget.Location),Delta,9000,true));
        
                MoveToward(MoveTarget, MoveTarget);
            }
        }   
        
       Sleep(1);
    }
}   

defaultproperties
{
    
}
 

yeah cant seem to figure out that code to work still trying to figure out when animation “rat attack” is played trigger a function.

maybe a way i can get around this with a touch event but not sure where to go about it.