Cast Ray Troubles
by Spencer Strombotne · in Technical Issues · 07/16/2008 (10:42 am) · 2 replies
I have the following code as a use button:
The problem is that wherever I click, It comes back as of type Player. Can anyone see where I've gone wrong?
function serverCmdUseButton(%client, %arg)
{
// scope the player
%player = %client.getControlObject();
// key is being pressed
if(%arg)
{
if(!%client)
{
return;
}
if(%player.isMounted == 1)
{
return;
}
// RAY_CASTING
//echo("%client: " @ %client);
//echo("%arg: " @ %arg);
//echo("%player: " @ %player);
// muzVec is the vector coming from the gun's "muzzle"
%muzVec = %player.GetEyeVector();
// muzNVec = normalized muzVec
%muzNVec = VectorNormalize(%muzVec);
// range of ray
%range = 10;
// scale muzNVec to the range the beam can reach
%muzScaled = VectorScale(%muzNVec, %range);
// muzPoint = the actual point of the gun's "muzzle"
%muzPoint = %player.GetEyePoint();
// rangeEnd = muzzle point + length of beam
%rangeEnd = VectorAdd(%muzPoint, %muzScaled);
%searchMasks = $TypeMasks::StaticObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::CorpseObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::ItemObjectType |
$TypeMasks::VehicleBlockerObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::WaterObjectType;
// search for objects within the beam's range that fit the masks above
%scanTarg = ContainerRayCast(%muzPoint, %rangeEnd, %searchMasks, %obj);
if(%scanTarg)
{
%serverID = getWord(%scanTarg,0);
echo("%scanTarg.getClassname(): " @ %scanTarg.getClassname());
echo("%scanTarg.getName(): " @ %scanTarg.getName());
switch$(%scanTarg.getClassname())
{
case StaticShape:
case Item:
%position = %serverID.GetPosition();
InfoBox("Object Information",%serverID,%position,"");
case Player:
//speakNPC(%client);
case WheeledVehicle:
// %serverID.mountObject(%player, 0);
// %player.isMounted = 1;
case FlyingVehicle:
//echo("Player is targeting a vehicle - Server ID = " @ %serverID);
// Do stuff
case HoverVehicle:
//echo("Player is targeting a vehicle - Server ID = " @ %serverID);
// Do stuff
case InteriorInstance:
//echo("Player is targeting a building - Server ID = " @ %serverID);
// Do stuff
case TerrainBlock:
//echo("Player is targeting the ground - Server ID = " @ %serverID);
// Do stuff
default:
}
}
}
// key is being released
else
{
// Do Stuff
}
}The problem is that wherever I click, It comes back as of type Player. Can anyone see where I've gone wrong?
About the author
#2
07/16/2008 (1:47 pm)
Yep James hit the nail on the head there.... should be %player used as %obj isn't even defined.
Associate James Ford
Sickhead Games