Author Topic: Fire a raycast from a player's position that checks if it hits a player  (Read 697 times)

Yeah, i'm making another mod, and I need a code that allows a player for fire a raycast from his Eye Vector, and then see if it collides with another Player, and if it works, return that player.

Code: [Select]
echo(containerRayCast($EyeVec,VectorScale($EyeVec,5),$TypeMasks::PlayerObjectType,-1));
Is what I tried.

$EyeVec is a variable I defined using this:

Code: [Select]
$EyeVec = findClientByName("Arukemo").player.getEyeVector();
Whenever I do the first code above, it returns 0. Help :c

Code: [Select]
function getEyeVectorPlayer(%cl)
{
if(!isObject(%cl.player))
return;

%pl = %cl.player;
%eye = vectorScale(%pl.getEyeVector(), 300);
%pos = %pl.getEyePoint();
%mask = $TypeMasks::PlayerObjectType;
%hit = firstWord(containerRaycast(%pos, vectorAdd(%pos, %eye), %mask, %pl));

if(!isObject(%hit))
return;

if(%hit.getClassName() $= "Player")
{
Echo(%hit);
}
}