Game Development Community

ContainerRayCast issue

by Robin Rudick · in Torque Game Engine · 01/01/2007 (8:51 pm) · 0 replies

Im trying to create a system for taking pictures in a game.

Right now the issue im having is the raycasting works, but the moment the player moves from the starting point, it no longer works correctly.

Here is the code i hope someone can help me with the issue.

function serverCmdSnapPicture(%client)
{
%player = %client.player;

%PlayerVec = %player.getForwardVector();
%playerPoint = %player.getWorldBoxCenter();
%selectRange = 300;
%playerScaled = VectorScale(%PlayerVec, %selectRange);
%rangeEnd = VectorAdd(%playerPoint, %playerScaled);
%searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::CorpseObjectType | $TypeMasks::ItemObjectType | $TypeMasks::RigidShapeObjectType;

echo(%PlayerVec);
%scanTarg = ContainerRayCast (%playerPoint, %rangeEnd, %searchMasks, %player);
if (%scanTarg)
{
%targetObject = firstWord(%scanTarg);
%distance = VectorSub(%playerPoint, %targetObject.getWorldBoxCenter());

echo("distance: ", %distance);
commandToClient(%client, 'TookPicture');
echo(%targetObject);
}
}