Forum

Detecting if the player is running away from his enemy?

Discuss Artificial Intelligence and Bot programming.

Moderator: InsideQC Admins

Detecting if the player is running away from his enemy?

Postby DusterdooSmock » Tue Jun 21, 2011 6:10 pm

I'm working on the AI for my mod, and I was wondering this:
If the player engages an enemy, is there a way to tell if the player is running away from the enemy that was engaged? And then, is there a way to tell if the player is ACTUALLY fighting the enemy, not just attacking the enemy, then leaving?
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby dreadlorde » Tue Jun 21, 2011 6:14 pm

Probably not without some heuristics. You could test if the player gets progressively further away from the monster after it see's/is attacked by the player.
Ken Thompson wrote:One of my most productive days was throwing away 1000 lines of code.

Get off my lawn!
User avatar
dreadlorde
 
Posts: 268
Joined: Tue Nov 24, 2009 2:20 am

Re: Detecting if the player is running away from his enemy?

Postby frag.machine » Wed Jun 22, 2011 12:42 am

DusterdooSmock wrote:I'm working on the AI for my mod, and I was wondering this:
If the player engages an enemy, is there a way to tell if the player is running away from the enemy that was engaged? And then, is there a way to tell if the player is ACTUALLY fighting the enemy, not just attacking the enemy, then leaving?


You could track the player's health and distance. If a player is sustaining a great amount of damage and the distance is getting bigger, then could assume it's fleeing.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2062
Joined: Sat Nov 25, 2006 1:49 pm

Re: Detecting if the player is running away from his enemy?

Postby DusterdooSmock » Wed Jun 22, 2011 6:14 am

frag.machine wrote:
DusterdooSmock wrote:I'm working on the AI for my mod, and I was wondering this:
If the player engages an enemy, is there a way to tell if the player is running away from the enemy that was engaged? And then, is there a way to tell if the player is ACTUALLY fighting the enemy, not just attacking the enemy, then leaving?


You could track the player's health and distance. If a player is sustaining a great amount of damage and the distance is getting bigger, then could assume it's fleeing.

What would be better to test the distance; a traceline or findradius?
I've already devised a system that will increase the distance to be checked every so often, but I don't know which one would be best suited for this..
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

use as directed. harmful if swallowed

Postby gnounc » Wed Jun 22, 2011 6:20 am

I would assume traceline. cant think of anything findradius would add if you're just checking for distance.

I mean if you already know the 2 poiints you need to form the traceline, then you dont really have anything you need to FIND.

traceline from self.origin (the monster being self, and the one calling the trace) to self.enemy.origin

save its distance
save its distance as old distance
save its distance
compare. distance with old distance

wash rinse repeat.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: use as directed. harmful if swallowed

Postby DusterdooSmock » Wed Jun 22, 2011 6:31 am

gnounc wrote:I would assume traceline. cant think of anything findradius would add if you're just checking for distance.

I mean if you already know the 2 poiints you need to form the traceline, then you dont really have anything you need to FIND.

traceline from self.origin (the monster being self, and the one calling the trace) to self.enemy.origin

save its distance
save its distance as old distance
save its distance
compare. distance with old distance

wash rinse repeat.

Haha. Thanks GnounC. I noticed the subject you put. I actually thought it was pretty funny..
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

;)

Postby gnounc » Wed Jun 22, 2011 6:56 am

no prob. let us know how it works when you get everything goin'.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: Detecting if the player is running away from his enemy?

Postby frag.machine » Thu Jun 23, 2011 1:06 am

DusterdooSmock wrote:
frag.machine wrote:
DusterdooSmock wrote:I'm working on the AI for my mod, and I was wondering this:
If the player engages an enemy, is there a way to tell if the player is running away from the enemy that was engaged? And then, is there a way to tell if the player is ACTUALLY fighting the enemy, not just attacking the enemy, then leaving?


You could track the player's health and distance. If a player is sustaining a great amount of damage and the distance is getting bigger, then could assume it's fleeing.

What would be better to test the distance; a traceline or findradius?


Code: Select all
distance = vlen (player.origin - monster.origin);
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2062
Joined: Sat Nov 25, 2006 1:49 pm

Postby DusterdooSmock » Fri Jun 24, 2011 7:36 pm

I did a little bit of browsing around in ai.qc, and i think that these might help. What do you think?

Code: Select all
/*
=============
infront

returns 1 if the entity is in front (in sight) of self
=============
*/
float(entity targ) infront =
{
   local vector   vec;
   local float      dot;
   
   makevectors (self.angles);
   vec = normalize (targ.origin - self.origin);
   dot = vec * v_forward;
   
   if ( dot > 0.3)
   {
      return TRUE;
   }
   return FALSE;
};


Code: Select all
/*
=============
visible

returns 1 if the entity is visible to self, even if not infront ()
=============
*/
float (entity targ) visible =
{
   local vector   spot1, spot2;
   
   spot1 = self.origin + self.view_ofs;
   spot2 = targ.origin + targ.view_ofs;
   traceline (spot1, spot2, TRUE, self);   // see through other monsters
   
   if (trace_inopen && trace_inwater)
      return FALSE;         // sight line crossed contents

   if (trace_fraction == 1)
      return TRUE;
   return FALSE;
};


I understand visible(), but i think i need an explanation of infront().
DusterdooSmock
 
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Postby Spike » Sat Jun 25, 2011 2:01 am

the vector*vector operator in qc is a 'dotproduct' operator

assuming they're normalized:
angle = acos(v1*v2);
or in other words:
cos(angle) = v1*v2;

so 0.3 is an frontal cone angle of about 75 degrees each way (not simple front only).
Spike
 
Posts: 2878
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby daemonicky » Sun Jun 26, 2011 2:37 pm

a) Dot product their directions (or velocities). Look for sign of result.
b) compare if distance between them gets larger
c) do b but use some statistics, epsilons, or cummulative change (sum of all changes in few miliseconds to approximate if he is moving in not being on the same spot) ...

frag.machine good idea tracking the health
Think, touch, movetype, solid, traceline ...
User avatar
daemonicky
 
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Postby MauveBib » Tue Jun 28, 2011 4:17 pm

This is a kinda fuzzy logic/heuristics area. There's no definite way to know if the player is running away, but checking the indications will get you close enough.

It's probably best to do it fuzzily; do several checks such as increasing distance, player view direction, player health etc and add a weighted figure to a check variable for each one, and if the total is higher than an arbitrary figure you can assume he's fleeing.
Apathy Now!
User avatar
MauveBib
 
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Postby daemonicky » Tue Jun 28, 2011 9:43 pm

... or make message box appear "Are You fleeing? - Yes, No, Cancel". ;-)
Think, touch, movetype, solid, traceline ...
User avatar
daemonicky
 
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm


Return to Artificial Intelligence

Who is online

Users browsing this forum: No registered users and 1 guest