Author Topic: Bad AI when npc chases pc.  (Read 838 times)

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« on: August 14, 2010, 12:56:31 pm »


               I have noticed that when the PC escapes from enemies following a
straight line, the enemies with melee weapon can't hit him, even if they
are more fast.I have tried to fix this, but I have not found a solution. Any idea?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #1 on: August 14, 2010, 03:45:49 pm »


               You could try something like if the PC is farther than 2 meters from the npc the npc will switch to their missile weapon and use that to attack the PC.  I use a little more complexity than that for some creatures, such as scouts, who will go into stealth and sometimes track the PC.  That has been quite a surprise to some people.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #2 on: August 14, 2010, 05:42:20 pm »


               Missle weapons = Lag though right?
               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #3 on: August 14, 2010, 08:04:22 pm »


               

Genisys wrote...

Missle weapons = Lag though right?


Really?
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #4 on: August 15, 2010, 10:37:24 pm »


               

Uther78 wrote...

Genisys wrote...

Missle weapons = Lag though right?


Really?


I thought I actually got around lag by giving some of my NPCs ranged weapons.  Instead of having to pathfind their way across a bridge or around buildings, they just start shooting.  Seems simple.
               
               

               
            

Legacy_Daybringer

  • Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #5 on: August 16, 2010, 01:31:16 am »


               Actually this guy posted such not too long ago on nwvault...



http://nwvault.ign.c....Detail&id=3761



Might help ^^;
               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #6 on: August 16, 2010, 07:30:13 am »


               

Daybringer wrote...

Actually this guy posted such not too long ago on nwvault...

http://nwvault.ign.c....Detail&id=3761

Might help ^^;



That guy is myself, I have tried to fix the problem with a speed penalty for the PC, but I dont like that solution, i prefer a fix for the npc A.I.
               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #7 on: August 25, 2010, 02:04:45 pm »


               I have made this script: it seems work



#include "x0_i0_position"



void main()





{

object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);



ClearAllActions();



if (GetDistanceToObject(oPC) < 8.0f)



if (GetDistanceToObject(oPC) > 3.0f)

{

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);



ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

}









ActionAttack(oPC);

}



               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #8 on: August 29, 2010, 02:55:28 pm »


               Nobody has an opinion?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #9 on: August 29, 2010, 05:14:45 pm »


               There are a number of problems with that script. So there you have an opinion.  Here is a little doctoring off the top of my head with some hopefully helpful comments or additions:

#include "x0_i0_position"
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
//effect eSpeed = EffectMovementSpeedIncrease(125);
//change number to change speed.  added for possible temporary speed increase.

ClearAllActions();
// you probably want to use the TRUE parameter here as this is likely to occur
// in combat otherwise the ClearAllActions call will have no effect.

if (GetDistanceToObject(oPC) < 8.0f)
//so do what if this condition exists, do nothing?  Maybe you wanted a return
//here or better switch to a ranged weapon if creature has one. If not just
// go into stealth and move away.
//Or maybe you are saying if the PC is within a certain range >3 and <8 meters
// do the following.  If so then write it as one statement:
//if ((GetDistanceToObject(oPC) >= 3.0f) && (GetDistanceToObject(oPC) <= 8.0f))
// do this the chase stuff, else do something else.  Condition not met PC is not
// between 3.0 and 8.0 meters, changed to or equal too.
if (GetDistanceToObject(oPC) > 3.0f)
{
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
//not sure that you need to keep repeating this.
//maybe use a delay command of a few seconds if the chasing
//npc seems to be losing it's target
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
}
//if (GetDistanceToObject(oPC) < 1.0f)
// added this in. So no point attacking unless you are actually there in contact

ActionAttack(oPC);

//else ActionMoveToLocation(GetAheadLocation(oPC), TRUE);
//ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSpeed, OBJECT_SELF, 3.0);
ActionAttack(oPC);
}
 
               
               

               


                     Modifié par ffbj, 29 août 2010 - 04:42 .
                     
                  


            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #10 on: August 30, 2010, 10:46:27 am »


               

ffbj wrote...

There are a number of problems with that script. So there you have an opinion.Etc...
 


Thank you very much.

Yes, I want the NPC charges the PC when is distance is between 3 and 8 meters. Your advice are helpful.

Your idea of a speed improvement during the charge is good.

I have repeated the ActionMoveToLocation because in this way the npc's charge seems more accurate and for the PC is more difficult to escape. I dont think that a delay will be useful.

The clearallactions without the TRUE attribute are uneffective, but the script worked all the same: then maybe is unnecessary to clear the actions.

here are the last part you added:

(//if (GetDistanceToObject(oPC) < 1.0f)
// added this in. So no point attacking unless you are actually there in contact

ActionAttack(oPC)'<img'>

that part seems now unnecessary because if the npc is already fighting null part of my script stop him (if we remove the clearallactions command).
               
               

               


                     Modifié par Uther78, 30 août 2010 - 12:20 .
                     
                  


            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #11 on: August 30, 2010, 06:59:52 pm »


               Errata corrige:

the clearallactions is necessary. It works even without "TRUE" because when the enemy chase NPC is not consedered "combat"
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #12 on: August 30, 2010, 11:39:47 pm »


               It's just good practice to do a Clear All Actions call before you proceed to other activities.  I recommend using the TRUE parameter since these actions are likely to occur around combat, thus the combatant being directed by them may still be flagged as being in combat.  But, that is along the lines of what I would do.  Just play with it and find out what works most closely to the sort of effects you are going for. Clear All Actions presuppose that there is something to clear.  Not really knowing what these npc might be doing otherwise.  For instance I have many monsters, creatures that will be just going about their busy, so following some activity.  Then if they spot an enemy there is a Clear All Action before going into combat, and also vice-versa.  The other way around when a creature has ended combat and goes back to doing some activity.  Of course you don't have to use it at all and may still get what you want.  This is just the approach I use, along a number of others who have advocated this use of the function.
               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #13 on: September 01, 2010, 08:39:19 am »


               Thx, if someone has an idea for improving the script, please post here.
               
               

               
            

Legacy_Uther78

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Bad AI when npc chases pc.
« Reply #14 on: September 01, 2010, 10:03:23 pm »


               Here is the updated script:



#include "x0_i0_position"







void main()







{





object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);



if (oPC != OBJECT_INVALID && GetIsEnemy(oPC))



if ((GetDistanceToObject(oPC) >= 3.0f) && (GetDistanceToObject(oPC) <= 8.0f))



{

ClearAllActions(TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

ActionMoveToLocation(GetAheadLocation(oPC), TRUE);

}









ActionAttack(oPC);

}



Note that the command "clearallactions" are applied only if the npc-PC distance is between 3 and 8: then if the npc is already fighting with a near PC the script dont stop him.