Detecting if the player is running away from his enemy?

Discuss Artificial Intelligence and Bot programming.
Post Reply
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Detecting if the player is running away from his enemy?

Post by DusterdooSmock »

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?
dreadlorde
Posts: 268
Joined: Tue Nov 24, 2009 2:20 am
Contact:

Post by dreadlorde »

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!
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

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

Post by frag.machine »

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)
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

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

Post by DusterdooSmock »

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..
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

use as directed. harmful if swallowed

Post by gnounc »

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.
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Re: use as directed. harmful if swallowed

Post by DusterdooSmock »

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..
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

;)

Post by gnounc »

no prob. let us know how it works when you get everything goin'.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

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

Post by frag.machine »

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)
DusterdooSmock
Posts: 170
Joined: Thu Aug 19, 2010 9:58 pm

Post by DusterdooSmock »

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().
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

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

Post by daemonicky »

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 ...
MauveBib
Posts: 634
Joined: Thu Nov 04, 2004 1:22 am

Post by MauveBib »

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

Post by daemonicky »

... or make message box appear "Are You fleeing? - Yes, No, Cancel". ;-)
Think, touch, movetype, solid, traceline ...
Post Reply