Detecting if the player is running away from his enemy?
Moderator: InsideQC Admins
13 posts
• Page 1 of 1
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?
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 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!
-

dreadlorde - Posts: 268
- Joined: Tue Nov 24, 2009 2:20 am
Re: Detecting if the player is running away from his enemy?
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Re: Detecting if the player is running away from his enemy?
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
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.
-

gnounc - Posts: 424
- Joined: Mon Apr 06, 2009 6:26 am
Re: use as directed. harmful if swallowed
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
Re: Detecting if the player is running away from his enemy?
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 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;
};
I understand visible(), but i think i need an explanation of infront().
- DusterdooSmock
- Posts: 170
- Joined: Thu Aug 19, 2010 9:58 pm
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).
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: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
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 ...
-

daemonicky - Posts: 185
- Joined: Wed Apr 13, 2011 1:34 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.
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!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
... or make message box appear "Are You fleeing? - Yes, No, Cancel". 
Think, touch, movetype, solid, traceline ...
-

daemonicky - Posts: 185
- Joined: Wed Apr 13, 2011 1:34 pm
13 posts
• Page 1 of 1
Return to Artificial Intelligence
Who is online
Users browsing this forum: No registered users and 1 guest