Game Development Community

Raycasting Not working in remote

by TigerHeros · in Torque 3D Professional · 08/05/2010 (11:25 am) · 2 replies

Hi All

function PlayGui::onMouseMove(%this, %screenPt, %start, %ray)
{
%ray = VectorScale(%ray, 100); // The distance to cast the ray
%end = VectorAdd(%start, %ray); // end = start point + ray vector
%mask = $TypeMasks::StaticObjectType |
$TypeMasks::StaticTSObjectType |
$TypeMasks::PlayerObjectType;
%exclude = ServerConnection.getControlObject(); // Don't hit ourselves
%result = ContainerRayCast(%start, %end, %mask, %exclude);
%name = %result.getname();
if(
%name$="RepBot" )
canvas.setCursor(HandCursor);
}


The Mouse Cursor is changing in local Machine. But When I am trying to connect with remote dedicated Server. The Mouse Cursor is Not Changing.

when i click i am receiving an error:

Unable to find Object '0' attempting to call function 'getName'

It is not working in remote.

Could any help me.Why the ray casting is not working in remote Machine?

Thanks in advance


#1
08/05/2010 (12:55 pm)
The script function ContainerRayCast() always casts a ray on the server container (aka: the server objects). The serverContainer only exists... in the server. So ContainerRayCast() does not work on remote clients.

You have two options:

1) Send a commandToServer() requesting the raycast, have the server cast the ray and return the results via commandToClient(). If your rayCast is meant to alter simulation objects (like destroying an object or something like that) this is the preferred way.

2) If you want to avoid the networking overhead and your rayCast is done for visual purposes, write a client-only version of ContainerRayCast():

ConsoleFunction( clientContainerRayCast, const char*, 4, 5, "( Point3F start, Point3F end, bitset mask, SceneObject exempt=NULL )"
                "Cast a ray from start to end, checking for collision against items matching mask.nn"
                "If exempt is specified, then it is temporarily excluded from collision checks (For "
                "instance, you might want to exclude the player if said player was firing a weapon.)n"
                "@returns A string containing either null, if nothing was struck, or these fields:n"
                "            - The ID of the object that was struck.n"
                "            - The x, y, z position that it was struck.n"
                "            - The x, y, z of the normal of the face that was struck.")
{
   char *returnBuffer = Con::getReturnBuffer(256);
   Point3F start, end;
   dSscanf(argv[1], "%g %g %g", &start.x, &start.y, &start.z);
   dSscanf(argv[2], "%g %g %g", &end.x,   &end.y,   &end.z);
   U32 mask = dAtoi(argv[3]);

   SceneObject* pExempt = NULL;
   if (argc > 4) {
      U32 exemptId = dAtoi(argv[4]);
      Sim::findObject(exemptId, pExempt);
   }
   if (pExempt)
      pExempt->disableCollision();

   RayInfo rinfo;
   S32 ret = 0;
   if (gClientContainer.castRay(start, end, mask, &rinfo) == true)	
      ret = rinfo.object->getId();

   if (pExempt)
      pExempt->enableCollision();

   // add the hit position and normal?
   if(ret)
   {
      dSprintf(returnBuffer, 256, "%d %g %g %g %g %g %g",
               ret, rinfo.point.x, rinfo.point.y, rinfo.point.z,
               rinfo.normal.x, rinfo.normal.y, rinfo.normal.z);
   }
   else
   {
      returnBuffer[0] = '0';
      returnBuffer[1] = '\0';
   }

   return(returnBuffer);
}
#2
08/06/2010 (9:06 am)
@Manoel Netro Thank You for Help.

I have compiled Successfully. But how can i identify the Object Name?

%result = ContainerRayCast(%start, %end, %mask, %exclude);
%result.getName()..

we can get the Object Name using containerraycast function.

%exclude = ServerConnection.getControlObject(); //what i should use here?

how can i get the ObjectName using ClientContainerRaycast function?

could u help me?