So, to shoot a raycast where you're looking, you have to do a couple of things.
1. Get the position that the eye is at, this is the start of the raycast.
2. Get the unit vector for where the person is looking. This is a normalized (exactly 1 long) vector that gives the point exactly 1 unit in front of the eye.
3. Stretch the unit vector to be longer than 1 unit. 1 unit is 2 brick studs, so I assume you want a longer range.
4. Add the stretched unit vector to the eye's position. This is the end of the raycast.
5. Cast the ray. The syntax for casting a ray is containerRaycast( start , end , typemask , exclude ).
1. Get the player's eye position
%startPoint = %player.getEyePoint();
2. Get the unit vector for where the person is looking.
%eyeVector = %player.getEyeVector();
3. Stretch the unit vector.
%stretchVector = vectorScale(%eyeVector, 50);
4. Add the stretched vector to the starting point
%endPoint = vectorAdd(%startPoint, %stretchVector);
5. Cast the ray.
%rayResult = containerRaycast(%startPoint, %endPoint, $TypeMasks::PlayerObjectType, %player);
So then just make a function for setting your look target's scale..
function serverCmdSetScale(%client, %size) {
%player = %client.player;
%startPoint = %player.getEyePoint();
%eyeVector = %player.getEyeVector();
%stretchVector = vectorScale(%eyeVector, 50);
%endPoint = vectorAdd(%startPoint, %stretchVector);
%rayResult = containerRaycast(%startPoint, %endPoint, $TypeMasks::PlayerObjectType, %player);
%targetPlayer = getWord(%rayResult, 0);
if(isObject(%targetPlayer))
%targetPlayer.setScale(%size SPC %size SPC %size);
else
messageClient(%client, '', "Target not found.");
}
Also, you can compress all that code into pretty much one line..
function serverCmdSetScale(%client, %size) {
return isObject(%targetPlayer = getWord(containerRayCast(%client.player.getEyePoint(), vectorAdd(%client.player.getEyePoint(), vectorScale(%client.player.getEyeVector(), 50)), $TypeMasks::PlayerObjectType, %client.player),0)) ? %targetPlayer.setScale(%size SPC %size SPC %size) : messageClient(%client, '', "Target not found.");
}