View previous topic :: View next topic |
Author |
Message |
redrum

Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York
|
Posted: Mon Nov 17, 2008 5:10 am Post subject: Angry Monsters??? |
|
|
In my QW server, I have monsters roaming around.
The problem is when a monster is chasing a player and he gets away he will not chase any other player.
I want to make it that the monster will chase the closest visible player.
I was playing with something like this in ai_run():
Code: | dist1 = self.origin - self.enemy.origin;
dist2 = self.origin - self.oldenemy.origin;
if (vlen(dist1) > vlen(dist2)
if (visible(self.enemy)))
if (visible(self.oldenemy))
{
self.enemy = world;
self.oldenemy = self.enemy:
HuntTarget ();
} |
The monster seems to "lock up". Like he's frozen or something?
Any help would be appreciated. _________________ Welcome to the Overlook Hotel 69.113.123.178:27500 |
|
Back to top |
|
 |
Electro
Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia
|
Posted: Mon Nov 17, 2008 9:50 pm Post subject: |
|
|
What you have there is only going to work if both the old player and the new player are both visible.
May I suggest just doing a function that's more like 'findenemy' and they just always go for the closest visible player. Don't need to worry about oldenemy really.
Maybe something like:
Code: |
local float bestdist, dist;
local entity e;
bestdist = 999999;
e = find(world, classname, "player");
while(e)
{
if (visible(e))
{
dist = vlen(e.origin - self.origin);
if (dist < bestdist)
bestdist = dist;
}
e = find(e, classname, "player");
}
|
...and maybe just do something like this per monster once per second or something? should be sufficient enough. _________________ Unit reporting!
http://www.bendarling.net/ |
|
Back to top |
|
 |
redrum

Joined: 28 Mar 2007 Posts: 367 Location: Long Island, New York
|
Posted: Mon Nov 17, 2008 10:45 pm Post subject: |
|
|
So, I make a new routine and place it in ai.qc?
And then call for it in ai_run()? _________________ Welcome to the Overlook Hotel 69.113.123.178:27500 |
|
Back to top |
|
 |
Electro
Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia
|
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Tue Nov 18, 2008 2:31 am Post subject: |
|
|
Just as an aside, when calling the routine, instead of calling every frame do something like:
if (random() < 0.1)
LookForEnemies();
This is useful for a few reasons. Firstly, it gives the monster a slight reaction time. Secondly, calling a search every frame for every monster is excessive and slow. Thirdly, using a random time rather than fixed intervals keeps each monster spread out on his searches. _________________ Apathy Now! |
|
Back to top |
|
 |
|