Game Development Community

Get access to the AI player

by Sergey Yo · in Torque Developer Network · 11/14/2009 (1:19 pm) · 1 replies

I see so the RayCast funcntion is not work on client side, and the friends helps me to modify the engine there this function works on client side, but another problem:

How can i gain control to client player , i found so the ServerConnection ID and Object group ID is not the same, can anybody puts me to the right way ?

What wrong in the function below ? :

function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
// find end of search vector
%ray = VectorScale(%ray, 2000);
%end = VectorAdd(%start, %ray);

// only care about terrain objects
%searchMasks = $TypeMasks::TerrainObjectType;

// search!
%scanTarg = ContainerRayCast( %start, %end, %searchMasks );
// If the terrain object was found in the scan

if( %scanTarg )
{
// Get access to the AI player we control
%cl = serverConnection.getId();
echo("Connection ID ", %cl);
%ai = ClientGroup.getObject(0).player;
echo("Player ID ",%ai);
// Get the X,Y,Z position of where we clicked
%pos = getWords(%scanTarg, 1, 3);
echo(%pos);
// Get the normal of the location we clicked on
%norm = getWords(%scanTarg, 4, 6);

// Set the destination for the AI player to
// make him move
%ai.setMoveDestination( %pos );

// If the AI player already has a decal (0 or greater)
// tell the decal manager to delete the instance of the gg_decal
if( %ai.decal > -1 )
decalManagerRemoveDecal( %ai.decal );

// Create a new decal using the decal manager
// arguments are (Position, Normal, Rotation, Scale, Datablock, Permanent)
// AddDecal will return an ID of the new decal, which we will
// store in the player
%ai.decal = decalManagerAddDecal( %pos, %norm, 0, 1, "gg_decal", true );

}

}

Sorry for my English and stupid questions, by i'm a nooby in Torque and dont speak English well.