Author Topic: Need help: How to make a tool that can hit bricks with ray-casting turned off.  (Read 610 times)

I am making a tool that needs to be able to hit bricks that have there ray-casting turned off, the same way the wrench can. Is there and extra bit of code I need to add or is there something in the standard code I need to change.

Ps the code is a weapon code but the thing is not a weapon, just incase that matters.

raycast with $TypeMasks::FxDTSBrickAlwaysObjectType

raycast with $TypeMasks::FxDTSBrickAlwaysObjectType

Um thanks, but could you explain it just a bit more, sorry I'm still kinda new with coding.

look at the old version of the Portal Gun (v8, not v9/v10) or either Gravity Gun for an example of a raycasting weapon

Code: [Select]
%ray = containerRayCast(%start,%end,%mask,%oneExemptObject);
if(%ray !$= "")
{
 //Hit something!
 %col = firstWord(%ray);
 %pos = posFromRaycast(%ray);
 %normal = normalFromRaycast(%ray);
}

%start and %end are the start and end points. Use %player.getMuzzlePoint(%slot) for the start and then add vectorScale(%player.getMuzzleVector(%slot),[range]) to get the end point.

For the mask, use the $TypeMasks::whateverObjectType variables. (look in console)
For more than one mask, separate them with | (bitwise OR) symbols. The Hammer might use something like this:
Code: [Select]
%mask = $TypeMasks::FxBrickObjectAlwaysType | //Targets the weapon can hit: All Bricks
$TypeMasks::PlayerObjectType | //AI/Players
$TypeMasks::StaticObjectType | //Static Shapes
$TypeMasks::TerrainObjectType | //Terrain
$TypeMasks::VehicleObjectType; //Vehicles
... and then check %col.getClassName() for what to do with the object.

The Exempt object might be the current player (firing player) so you can't hit yourself or something similar.

Thank you, I'l tinker around and see if I can fit it into what I'm doing.