Angry Monsters???
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
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():
The monster seems to "lock up". Like he's frozen or something?
Any help would be appreciated.
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: Select all
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: The-Overlook-Hotel.game-server.cc
-

redrum - Posts: 410
- Joined: Wed Mar 28, 2007 11:35 pm
- Location: Long Island, New York
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:
...and maybe just do something like this per monster once per second or something? should be sufficient enough.
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: Select all
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.
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
Yeah sure, why not 
Benjamin Darling
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
http://www.bendarling.net/
Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
- Electro
- Posts: 312
- Joined: Wed Dec 29, 2004 11:25 pm
- Location: Brisbane, Australia
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.
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!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest