Detecting if the player is running away from his enemy?
-
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Detecting if the player is running away from his enemy?
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?
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?
-
- Posts: 268
- Joined: Tue Nov 24, 2009 2:20 am
- Contact:
-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm
Re: Detecting if the player is running away from his enemy?
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.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?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC (LordHavoc)
-
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: Detecting if the player is running away from his enemy?
What would be better to test the distance; a traceline or findradius?frag.machine wrote: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.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?
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..
use as directed. harmful if swallowed
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.
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.
-
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
Re: use as directed. harmful if swallowed
Haha. Thanks GnounC. I noticed the subject you put. I actually thought it was pretty funny..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.
-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm
Re: Detecting if the player is running away from his enemy?
DusterdooSmock wrote:What would be better to test the distance; a traceline or findradius?frag.machine wrote: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.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?
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)
-
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
I did a little bit of browsing around in ai.qc, and i think that these might help. What do you think?
I understand visible(), but i think i need an explanation of infront().
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;
};
-
- Posts: 185
- Joined: Wed Apr 13, 2011 1:34 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
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 ...
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.
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!
-
- Posts: 185
- Joined: Wed Apr 13, 2011 1:34 pm