Page 1 of 1
Q3 -changing the bot view angle
Posted: Thu Jan 31, 2008 10:37 am
by gumstic
Hi,
I'm trying to change the way a bot views in quake 3. I'm not sure whether the code I'm fiddling with is the right stuff.
ai_dmq3.c has a function to find an enemy and is also where some code is set for the bot viewing area (to see an enemy).
Does anyone know how to change this, because it seems a bit harder than I thought...
...a Q3Mod noob

Re: Q3 -changing the bot view angle
Posted: Thu Jan 31, 2008 11:34 am
by ^misantropia^
Counterquestion: why do you need to change the view angle? There may be different solutions, depending on what it is you are trying to accomplish.
Re: Q3 -changing the bot view angle
Posted: Thu Jan 31, 2008 9:01 pm
by gumstic
Ok,
The bot normally has a view angle of 90 degrees for detecting enemies, right?
I'm trying to make the non-view-angle (outside the 90 deg.) to be like a special "detection area" that the bot will use with specific fuzzy rules (events) to act upon when an enemy moves within this non-viewable area of the bot.
This will create more interesting "human-like" actions that the bot can make if being i.e. approached from behind.
Hope this sounds a bit more logical...
Re: Q3 -changing the bot view angle
Posted: Thu Jan 31, 2008 9:53 pm
by ^misantropia^
Ah, you mean field of vision. A quick 'n' dirty solution:
1. Set the FOV for all bots to 360.
2. When a bot detects the player:
2a. Calculate the angle between the two, and
2b. Pick a course of action depending on the outcome of 2a.
Let me know if you need clarification or pointers.
Re: Q3 -changing the bot view angle
Posted: Fri Feb 01, 2008 5:15 pm
by gumstic
Hm, sounds feasible, but wouldn't that just switch (upon some detection) to a specific angle, or not? I may have something confused here...
Or should I be thinking at a "line" angle pointing strait to a direction the bot detects a player (around the 360 deg.), that way setting specific angles to reactions the bot would take for each case.
Am I on track ?
Re: Q3 -changing the bot view angle
Posted: Fri Feb 01, 2008 9:40 pm
by ^misantropia^
Yeah, but allow me to explain a little as I took a shortcut with point 2a. You'll want the angle relative to the bot's current (2D) view angle. So if:
1. the player is at position (5, 5)
2. the bot is at position (10, 10), and
3. the bot is looking straight to the north (0 degrees clockwise), then
4. the player is at a 225 degree angle to the bot (south west), and hence not visible
Not visible, but perhaps audible. For extra spice, you can take other variables into account, like the distance between the player and the bot, the players view angle, direction and velocity. I hope I've made it a bit clearer, but if not, don't hesitate to say so.
Re: Q3 -changing the bot view angle
Posted: Fri Feb 01, 2008 11:26 pm
by gumstic
Excellent! I'll try it out and hope it works.

Thanks
Re: Q3 -changing the bot view angle
Posted: Sat Feb 02, 2008 11:13 pm
by gumstic
Ok, I'm trying to change the "fov" for the bots, but don't seem to be that simple.
The only logical place I see to add this "view feature" (board topic) is in the ai_dmq3.c
file within the "BotFindEnemy" function, but there's no "fov" here. The only thing that
could possibly be modified is:
Code: Select all
//check if the enemy is visible
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, f, i);
if (vis <= 0) continue;
BotEntityVisible is declared as: (int viewer, vec3_t eye, vec3_t viewangles, float fov, int ent).
So this means the "f" is poiting to the "fov", but is a little confusing and I don't fully
understand it and also whether I'm working in the right spot or not

.
Any help appreciated...
Re: Q3 -changing the bot view angle
Posted: Sun Feb 03, 2008 11:39 am
by ^misantropia^
Patch the InFieldOfVision() function in ai_dmq3.c so that the fov is always 360. Thousands of refactoring consultants are crying out in horror now, but don't let that bother you.
Re: Q3 -changing the bot view angle
Posted: Sun Feb 03, 2008 4:14 pm
by gumstic

oh, yes I'm sure of that, but if we think that it has been written quite a long
time ago, I will just lay back refactoring.
Ok, I tried changing the InFieldOFView to always see 360. I think its working. Now for
my next step I added the following to the "findEnemy" function, but don't think it works
correctly. It notes the Print output once for 270 (which is a test degree), but not
sure if it works properly.
Here's what I messed with:
Code: Select all
//check if the enemy is visible
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, f, i);
if (vis <= 0) {
BotAI_Print( PRT_MESSAGE, "AGENT SAYS: Enemy is detectable.\n"); //gmod
continue;
}
detect = findradius (detect, bs->enemyorigin, 270);
if (detection = 270)
BotAI_Print( PRT_MESSAGE, "AGENT SAYS: Enemy is detected at 270.\n"); //gmod
Now, findradius is a function that calculates the radius between 2 objects (hopefully)
and so I just set that to get some feedback from the screen if it matches when the
player is 270 deg. towards the bot.
Making any sense

Re: Q3 -changing the bot view angle
Posted: Sun Feb 03, 2008 10:11 pm
by ^misantropia^
Classic error. You are doing assignment instead of comparison here (that is, you're setting detection to 270). This is what you are after:
I take it findradius() is a function you wrote? Could you post its source?
Re: Q3 -changing the bot view angle
Posted: Mon Feb 04, 2008 12:29 pm
by gumstic
That's right, it's a plugged-in function sitting in the g_utils.c file in the Game project and the code is originally from the book "Mod programming in quake III arena" (by Shawn Holmes), here it goes:
Code: Select all
gentity_t *findradius (gentity_t *from, vec3_t org, float rad)
{
vec3_t eorg;
int j;
if (!from)
from = g_entities;
else
from++;
for (; from < &g_entities[level.num_entities]; from++)
{
if (!from->inuse)
continue;
for (j=0; j<3; j++)
eorg[j] = org[j] - (from->r.currentOrigin[j] + (from->r.mins[j] + from->r.maxs[j])*0.5);
if (VectorLength(eorg) > rad)
continue;
return from;
}
return NULL;
}
Re: Q3 -changing the bot view angle
Posted: Thu Feb 07, 2008 11:23 am
by gumstic
I don't seem to get any sign that this is working...
one question: how could I display a variable to the screen. I'm trying with this
radius but, I can only get the memory address output. What should I put to get the
actual value of the variable output ?
thx
Re: Q3 -changing the bot view angle
Posted: Sat Feb 09, 2008 10:45 am
by AnthonyJ
gumstic wrote:I'm trying with this radius but, I can only get the memory address output.
... and that is why its not working. The findradius function doesnt return you a distance to another entity, its for finding any entities that are within the radius. The return value is the pointer to the entity it found.
I'd suggest you avoid using functions like that which you don't understand - either write your own function which does what you want, or try to understand the what the findradius func does, and use that the way it was intended.