Inside3D!
     

Angry Monsters???

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
redrum



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Mon Nov 17, 2008 5:10 am    Post subject: Angry Monsters??? Reply with quote

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
View user's profile Send private message Send e-mail
Electro



Joined: 29 Dec 2004
Posts: 241
Location: Brisbane, Australia

PostPosted: Mon Nov 17, 2008 9:50 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
redrum



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Mon Nov 17, 2008 10:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Electro



Joined: 29 Dec 2004
Posts: 241
Location: Brisbane, Australia

PostPosted: Tue Nov 18, 2008 12:14 am    Post subject: Reply with quote

Yeah sure, why not Smile
_________________
Unit reporting!
http://www.bendarling.net/
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
MauveBib



Joined: 04 Nov 2004
Posts: 602

PostPosted: Tue Nov 18, 2008 2:31 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group