Author Topic: Raycasts  (Read 477 times)

I am wondering about raycasts. How would I fire a raycast, and then have something happen where it hits?

%raycast = containerRayCast(%start,%end,%mask,%ignore);
The raycast returns several things. If it doesn't hit anything of said mask, then it will return null, but if an
object of the same typemask as %mask, then it will return the object id, position, and the normal (possibly more, can't remember). I forget how the ignore argument works (it is optional, as it defaults to null); I can't remember if you put in a certain object, or a typemask.

Here is how you would fire a raycast from a player to where they are looking, searching for a brick:
Code: [Select]
%eyePoint = %client.player.getEyePoint();
%eyeVector = %client.player.getEyeVector();
%Range = vectorAdd(%eyePoint,vectorScale(%eyeVector,10));
%raycast = containerRayCast(%eyePoint,%Range,$TypeMasks::fxBrickObjectType);
Now to get the brick you could do this:
Code: [Select]
%obj = firstWord(%raycast);
is(isObject(%obj))
{
   //Do stuff
}

You can also use these functions to get the normal and position from raycasts easily without using getWord:
Code: [Select]
posFromRaycast(%raycast)
normalFromRaycast(%raycast)