Computer player detecting live player
by Kevin La Barre · in Torque Game Engine · 02/27/2004 (12:09 pm) · 5 replies
I'm thinking this may be doable via scripting alone. If not, I'll repost in the private forums.
I'm curious how others are/would handle this. Basically I would like to have my computer controlled characters respond to a player once the player gets with a specific range (10 meters for example).
This needs to be a fairly efficient process since many MANY computer controlled players may exist and I'm not exactly sure how a loop type thing would work.
Opinions?
I'm curious how others are/would handle this. Basically I would like to have my computer controlled characters respond to a player once the player gets with a specific range (10 meters for example).
This needs to be a fairly efficient process since many MANY computer controlled players may exist and I'm not exactly sure how a loop type thing would work.
Opinions?
#2
You could look at that to get some clues.
Im not sure how to do it but i think they used a container ray search to find objects within range??
02/27/2004 (2:01 pm)
Tribes 2 has some AIPlayer script that does that i think.You could look at that to get some clues.
Im not sure how to do it but i think they used a container ray search to find objects within range??
#3
02/27/2004 (2:14 pm)
Calculate the distance between the players and the AIs.... if any are less than the threshold, trigger your action. This will be pretty efficient. It can be made more efficient if you do a quadtree sort of thing so you can just query the tree instead of iterating over everything.
#4
02/27/2004 (2:37 pm)
Couldn't you just do a ContainerRadiusSearch for each client/human player, that searches for the computer controlled players and informs them, that the client came in range? This could be scheduled, too. This would probably be more efficient than checking all human and computer controlled players. If you need different ranges for different computer controlled players, then set the container search radius to the maximum range and let each computer controlled player do a check if the client is really in range.
#5
If there are less human players then have them detect the bots and inform the bots that they are in range. Much smaller set to process then.
02/27/2004 (3:05 pm)
Stefan is right about one thing, you need to look at this from the other angle. If there are less human players then have them detect the bots and inform the bots that they are in range. Much smaller set to process then.
Torque Owner Pascal
I think you'd want to do it in C++ because you're looking at a fair amount of vector math for each brain tick to figure out which player is the closest. If you don't want to do that, you could use the script schedule command to calls a update function, iterate through each memeber of the "ClientGroup" and do the following check the play distance. Here's some untested code (for what its worth). you could call aiCheck in a object onAdd method to start the process:
function aiCheck(%enemy) { %objPos = %enemy.getWorldBoxCenter(); for(%i = 0; %i < ClientGroup.getCount(); %i++) { %conn = %ClientGroup.getObject(%i); %player = %conn.player; %eyePoint = %player.getWorldBoxCenter(); %distance = VectorDist(%objPos, %eyePoint); if(%distance < WHATEVER_DISTANCE_VALUE) { // chase / attack / etc } } schedule(500,0,"aiCheck",%enemy); // check every 1/2 second }there is also a couple of resources on it, one by Stefan Moises I can remember:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3746
-Pascal