Page 1 of 1

Detecting if the player is running away from his enemy?

Posted: Tue Jun 21, 2011 6:10 pm
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?

Posted: Tue Jun 21, 2011 6:14 pm
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.

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

Posted: Wed Jun 22, 2011 12:42 am
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.

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

Posted: Wed Jun 22, 2011 6:14 am
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..

use as directed. harmful if swallowed

Posted: Wed Jun 22, 2011 6:20 am
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.

Re: use as directed. harmful if swallowed

Posted: Wed Jun 22, 2011 6:31 am
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..

;)

Posted: Wed Jun 22, 2011 6:56 am
by gnounc
no prob. let us know how it works when you get everything goin'.

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

Posted: Thu Jun 23, 2011 1:06 am
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);

Posted: Fri Jun 24, 2011 7:36 pm
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().

Posted: Sat Jun 25, 2011 2:01 am
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).

Posted: Sun Jun 26, 2011 2:37 pm
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

Posted: Tue Jun 28, 2011 4:17 pm
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.

Posted: Tue Jun 28, 2011 9:43 pm
by daemonicky
... or make message box appear "Are You fleeing? - Yes, No, Cancel". ;-)