Game Development Community

How can i Make the AI Player should follow the Player

by CloudFire · in Torque Developer Network · 04/30/2010 (3:08 am) · 6 replies

In My project

I have to display Many AI Player.I have displayed. but my problem is

I have to make all the AI Player should follow the player.

how can i make all the AI Player should follow the player.

any ideas welcome.


Thanks in advance

#1
04/30/2010 (4:00 pm)
AIPlayer.setMoveDestination(player.position);

put something like that inside of the AIManager
#2
05/03/2010 (5:03 am)
@Realm X Thank You for your reply.

I have apply ur method. But The AI player is not following the player.

when the player moves the ai player also should follow.

#3
05/03/2010 (7:19 pm)
Once it moves to the position it calls some kind of function <datablock>::onReachDestination (I think) at that point you have to tell it to do something else. try repeating the command.

But if he isn't moving at all it's because when Realmx says AIPlayer.setMoveDestination(player.position); he means <AIPlayer meaning the id or name of your AI player>.setMoveDestination(<player meaning your players ID>.position);

example:

%this.setMoveDestination(localClientConnection.player.position);

Note: only good for single player.
#4
05/03/2010 (10:14 pm)
Here is an alternate way that should work in multiplayer in this case Im just telling the mob to chase the nearest target (on each destination it would pick the current closest again).

add this in AIPlayer.cs.

function PlayerData::onReachDestination(%this,%obj)
{
   %playerClient = %obj.getNearestPlayerTarget(); //returns the index of nearest client
   %playerClient = ClientGroup.getObject(%playerClient);//convert from index to ID
   %obj.setMoveDestination(%playerClient.player.position);

}

This is ugly because it doesn't have any decision making process and the bot never stops trying to get to your exact position but I tested it and it worked in T3D alpha 1.1
Also its under PlayerData because that is the parent to the bots datablock and could be different for you.

It's hard to make suggestions when there is no way to tell from your previous posts how advanced you are.
#5
05/03/2010 (10:20 pm)
oh yeah, and the bot doesn't just up and start running after spawning. Since this is called onReachDestination he of course has to be ending some kind of a move to trigger this.

I got his ID by raycasting him then sent him this command
<ID>.setMoveDestination(localClientConnection.player.position);


#6
05/03/2010 (10:39 pm)
I had some trouble calling the function by the datablock name because it was named Gideon. I think it was because the cs file Gideon was in was also called Gideon renamed the datablock to GideonData and was able to call the function by GideonData::onReachDestination(%this,%obj)

So this should help you seperate out different creatures actions.