Forum

Angry Monsters???

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Angry Monsters???

Postby redrum » Mon Nov 17, 2008 5:10 am

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: 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
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Electro » Mon Nov 17, 2008 9:50 pm

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: 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/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Postby redrum » Mon Nov 17, 2008 10:45 pm

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: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Electro » Tue Nov 18, 2008 12:14 am

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/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Postby MauveBib » Tue Nov 18, 2008 2:31 am

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


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest