Getting AI to attack me
by Chrisamethyst · in Technical Issues · 03/30/2007 (1:06 pm) · 2 replies
After adding a bot in bot.cs I'd like him to attack me. I have it so that when he senses my presence he will come after me and keep following me. But how do I get him to attack (melee style). I attempted the melee tutorial but I'm not sure where to add the last two steps. I added this code to bot.cs:
This function makes the bot follow me when he sees me... where and what kind of code could I add for him to hit me with a meele weapon (preferably hitting me with his arm--which is an animation)?
function AIPlayer::seekPlayer(%this){
%ppos = $player.getTransform();
%bpos = %this.getTransform();
echo("player" SPC %ppos SPC "bot" SPC %bpos);
%dist = vectorSub(%ppos,%bpos);
if(%dist<20.0){
%this.setMoveDestination( %ppos , true);
%this.followPath("");//don't follow the path
}
//this scheduling is where the aiplayer will think
//before he hits the player...
%this.schedule(500,seekPlayer);
}This function makes the bot follow me when he sees me... where and what kind of code could I add for him to hit me with a meele weapon (preferably hitting me with his arm--which is an animation)?
#2
Also, you'll need to define %player in the function parameters/arguments (i get those two mixed up)
04/28/2007 (10:01 am)
Also, you'll need to use a %this.setAimObjectAlso, you'll need to define %player in the function parameters/arguments (i get those two mixed up)
Torque Owner Caleb
Default Studio Name
After doing another vectorDist or vectorSub check to see if the player is in sword range, you can use setImageTrigger(0, true); to use the weapon in slot 0, setImageTrigger(0, false) to make him stop.