Help with raycasts

Author Topic: Help with raycasts  (Read 679 times)

Well, I've been stuck on something for a while. I have made an add-on that is extremely close to completion. The only thing in the way is the special scripts. It involves firing a raycast from the player to an object in the distance. I'm not sure how to do that, for another person is doing my code. He seems stuck too, so I might as well ask and see if I can get anything from the collective knowledge of Blockland's modders. Here is the code so far:
Code: [Select]
%obj = %obj.getMountedObject(0);
%client = %obj.client;

if($sim::time-3 < %client.lockOnDelay)
return;

%obj.client.play2d(genericbeep);
if(isObject(%client))
ServerCmdUnUseTool(%client);

%start = vectorAdd(%obj.getPosition(), "0 0 0");
%end = vectorAdd(%start, vectorScale(%obj.getEyeVector(), 1000));
%typemasks = $Typemasks::VehicleObjectType;
%target = containerRaycast(%start, %end, %typemasks, %obj);
The first %obj is the turret itself, getting the player mounted in seat 0. The issue is that, it registers the target when it's at eye level, but it does not work at all when the turret is raised. Does anyone know what I'm doing wrong?

You are using %obj.getEyeVector(), of course it uses their eye level


Okay, so I realized this should work, except it seems to be shooting from the player's face itself. When leaning back I realize I get a hit underneath it. Can I make it shoot from the actual player's view, and not the physical face? Once again, here's the area around the code I think edited a little:
Code: [Select]
%obj = %obj.getMountedObject(0);
%client = %obj.client;

if($sim::time-3 < %client.lockOnDelay)
return;

%obj.client.play2d(genericbeep);
if(isObject(%client))
ServerCmdUnUseTool(%client);

%start = %obj.getEyePoint();
                                %end = vectorAdd(%start, vectorScale(%obj.getEyeVector(), 1000));
%typemasks = $Typemasks::VehicleObjectType;
%target = containerRaycast(%start, %end, %typemasks, %obj);


if(!isObject(%target) || %target == %mount.getObjectMount())
{
%client.centerPrint("No lock!",1);
return;
}