getEyeVector/Position of where player is looking

Author Topic: getEyeVector/Position of where player is looking  (Read 984 times)

I am attempting to get the position of where a player is looking like the /warp command. I tried using player.getEyeVector which I thought would do this but it didn't really work. Can someone tell me either how the /warp command works or how I would go about doing this?

do a raycast from getEyePoint in the direction of getEyeVector

do a raycast from getEyePoint in the direction of getEyeVector
I tried doing that but I wasn't too sure how to, could you try to explain?

Code: [Select]
%player = blah;
%start = %player.getEyePoint();
%end = vectorAdd(%start, vectorScale(%player.getEyeVector(), 400));

//hit bricks and the ground plane
%mask = $TypeMasks::FxBrickObjectType | $TypeMasks::TerrainObjectType;

%result = ContainerRayCast(%start, %end, %mask, %player);

if(isObject(%result))
{
    %lookposition = posFromRaycast(%result);
    //do stuff
}


Code: [Select]
%result = ContainerRayCast(%start, %end, %mask, %player);

if(isObject(%result))

That is bad practice, as %result would be a multiple word string containing a lot of other information. The first word would be the object that the raycast hit (if it hit one), so you should be using if(isObject(getWord(%result, 0)))

function Player::getEyeFocus(%this)
{
  %start = %this.getEyePoint();
  %path = vectorScale(%this.getEyeVector(), 512);
  %end = vectorAdd(%start, %path);
  %ray = containerRayCast(%start, %end, -1, %this);

  if (%ray)
    return getWords(%ray, 1, 3);

  return %end;
}

That is bad practice, as %result would be a multiple word string containing a lot of other information. The first word would be the object that the raycast hit (if it hit one), so you should be using if(isObject(getWord(%result, 0)))
It works perfectly as torque will use the first word of a string when trying to convert it to an object id.

It works perfectly as torque will use the first word of a string when trying to convert it to an object id.

But yet it
is bad practice

If someone new to raycasts were to read that, they would assume that containerRaycast returns a single object, and nothing more, then the posFromRaycast does some fancy magic stuff.