Game Development Community

Cannibal Bots

by Jared Hoberock · in Torque Game Engine · 03/18/2002 (4:32 pm) · 4 replies

How would I get a function to constantly (or at least every few seconds) to run without hindering the gameplay? (Infinite loops are bad.)

You see, I've got bots running around, and I want to make them cannibals. Well, I've got them hurting me when they get so close, but they only hurt me when they execute their onReachLocation function. So, I don't get hurt until I move away from them and they can actually get to my old position.

Here's my code:

function AIPlayer::onReachDestination(%this) {
...
aiPlayer::senseAndHurtPlayer(%this);
...
}

and

function AIPlayer::senseAndHurtPlayer(%this) {
%playPos = $human.getPosition();
%botPos = %this.getLocation();
%dist = VectorDist(%playPos, %botPos);

if (%dist <= 2) {
echo("Damage Me");
$daPlaya.applyDamage(2);
} // End if
}

Thanks,
D

#1
07/23/2002 (6:52 pm)
Hey Jared,

What i am doing is making the bots check if the target is within a specified radius. If they are not then i make them go to the same location they are already at. this will call the on reach destination function again.

for your on reach destination problem, i am using the method onCollision to tell when i bump into another player or aiplayer.

sorry for the late reply.
#2
07/24/2002 (7:12 pm)
A very well kept secret of the Torque engine is the fact that you can schedule function calls from the script. My AI calls this function in the onAdd():


function onStartScan(%this)
{
echo( "I've been added." );
AIPlayer::handleWaypointsAndChase(%this);

if(!$aggro)
{
schedule(250, 0, "onStartScan", %this);
// echo("scanning");
}
}

Where $aggro is a boolean which is true if they've found a target. This function checks to see if there is a target, and if there isn't, schedules itself to be called again in a little while. Also, I've added another callback in AIPlayer.cc which gets called every frame, rather than on a pre-defined action, like onReachDestination. Makes the bots update every frame rather just when the get to where they were going. That makes for a very jerky AI.
#3
07/24/2002 (7:39 pm)
Hey Robert,

Your callback every frame function sounds very promising.

Does it hinder the frame rate much?
#4
07/25/2002 (4:56 pm)
Doesn't hinder the frame rate at all. The Torque engine is really a very impressive piece of technology. I've run the multiplayer with about 15 bots chasing me and there was some frame rate loss, but not anything too noticeable. (It looked like the end of a Benny Hill episode, all that was missing was the music, hehe) I really attribute that to the fact that the only model I'm using right now has about 2700 poly's and my world is super-detailed. Before I even coded the AI there was frame loss with that many models on screen at once.