Game Development Community

Spawning AI Over a network

by Djekko Spurgin · in Torque 3D Beginner · 04/28/2016 (5:02 am) · 2 replies

I'm trying to add some AI to my multiplayer game. There is no shooting or weapons in the game. In single player I can spawn a player fairly easy and I can have it follow me as well but when i run a server and try and run the same commands it doesn't work. This is the code i currently have

function SpawnFollowingAI (%AIname){
	
	new AIPlayer(%AIname) { 
	datablock = "DefaultPlayerData"; 
	position = LocalClientConnection.Player.getPosition(); 
	};
	
	%AIname.setAimObject(Player);
	
	schedule(2000,0,"FollowPlayer",%AIname);
}

function FollowPlayer(%AIname){
	echo("AI is Following Player");
	
	//echo(LocalClientConnection.Player.getTransform();
	
	%AIname.setMoveDestination(LocalClientConnection.Player.getTransform());
	
	schedule(500,0,"FollowPlayer",%AIname);
}

I know the main problem is around this line

position = LocalClientConnection.Player.getPosition();

but i cant help but think there are some other issues. Iv'e tried spawning the AI player at a spawn sphere but I probably did it wrong.

Any Ideas on how i could go about this would be great

#1
04/28/2016 (5:42 am)
Read this, since it covers this exact scenario for spawning:
http://www.roostertailgames.com/TorqueRef/content/documentation/Scripting/Advanc...
Using LocalClientConnection won't work when you're the client connected to a server. You have to make a serverCmd and call commandToServer() from your script to have the server do the work.
Additionally, you'll want to add serverCmds for telling the AI units to follow players as well.
#2
04/28/2016 (6:35 am)
ok thanks for the help