Game Development Community

Raycast terrain issue

by Howard Dortch · in Torque 3D Professional · 11/02/2010 (7:56 pm) · 2 replies

I am trying to do a line of sight test between 2 objects. I have the mask set to $TypeMasks::StaticShapeObjectType. I place one object in plain sight of the other and cast a ray and echo "HIT"... all is well.. I move one object over a hill so I can't see the other one, do the raycast and I still get a "HIT" it's like the terrain isn't there. Anyone know what the trick is to make the terrain occlude the raycast ?



#1
11/02/2010 (8:48 pm)
Raycasts can only "hit" the typemasks you tell them to stop at. So make a "master" typemask as a global and it will intersect with them all. Then make a script to decide what to do with each type of object encountered.

eg:

$Obstacles = 
  $TypeMasks::VehicleObjectType |
  $TypeMasks::PlayerObjectType |      
  $TypeMasks::TerrainObjectType |     
  $TypeMasks::StaticTSObjectType |    
  $TypeMasks::StaticShapeObjectType |
  $TypeMasks::ForestObjectType;     // InteriorObjectType removed

function ClearView(%this, %obj)
{
   if(!isObject(%obj)) return false;

   %start = %this.getTransform();
   %end = %obj.getTransform();

   %targetsearch = containerRayCast(%start, %end, $Obstacles, %this.getID());

   %impactpoint = firstWord(%targetsearch);
   if(%impactpoint.getClassName() $="StaticShape")
   {
      echo("HIT Staticshape!");
      return true;
   }
   else
   {
      echo("Missed StaticShape - has hit " @ %impactpoint.getClassName());
      return false;
   }
}
#2
11/02/2010 (10:30 pm)
I see it now...Thanks mucho...