Making an Enemy AI Chase the Player
by Jonathan Spencer Ferrell · in General Discussion · 02/15/2009 (7:53 pm) · 3 replies
Hello!
I'm working on a project for my college class and I'm (very) new to Torque. Right now I'm working on an AI enemy. This is what I want the enemy to do:
1) Follow a path while waiting for the player to be in range
2) When the player is in range, mark it's current location as a variable and chase the player
3) When the player leaves its range, return to the marked location and continue following the path
So far my enemy is following a path but it will not chase the player yet. I'm guessing I need to make a new function which I will call chasePlayer() and have it test the distance between the player and the enemy and tell the enemy to move to the player's location when it's in a certain range. Can anyone tell me how to do that?
Thanks in advance!
I'm working on a project for my college class and I'm (very) new to Torque. Right now I'm working on an AI enemy. This is what I want the enemy to do:
1) Follow a path while waiting for the player to be in range
2) When the player is in range, mark it's current location as a variable and chase the player
3) When the player leaves its range, return to the marked location and continue following the path
So far my enemy is following a path but it will not chase the player yet. I'm guessing I need to make a new function which I will call chasePlayer() and have it test the distance between the player and the enemy and tell the enemy to move to the player's location when it's in a certain range. Can anyone tell me how to do that?
Thanks in advance!
#2
02/16/2009 (8:13 am)
Thanks Shane! The part that explained the setMoveDesination() was just what I needed. I made a lot of adjustments and now my ai character will chase the player. So now I'm working on the functions to add to my ai enemy's script. I have it so that the functions will schedule themselves after they execute. However, they don't execute the first time until I call them in the console. Where do I need to call the function so that it runs when I start the game?
#3
I'm not too sure about this. Did you try searching the TDN? That is where I found the other link I gave you.
02/16/2009 (8:19 am)
Hmm. Take a look in your 'game.cs' & your 'init.cs'. I think one of those you must execute your file like so:// Execute my AI Player
exec("./[b]yourpath[/b]/myaiplayerI'm not too sure about this. Did you try searching the TDN? That is where I found the other link I gave you.
Torque Owner Shane09
NOTE: To achieve what you are looking for, it might take a little changes. However, it is entirely possible. This is most likely the base for what you are attempting to accomplish, though.