Author Topic: Bullet entry?  (Read 1046 times)

Title says all. I know this is possible because I've seen it before in places, but what is the actual/psuedo code for making this work? With arguments:

integer - how many surfaces/bricks the bullet can travel through
datablock/string - what kind of datablock objects the bullet can travel through, like Players, Bots, Vehicles
float - what percentage of the projectile's direct damage is lost per surface entry

Explosions spawned on the bullet's entry of a surface - different from the bullet's final impact


^ if these can be incorporated into it, I would be greatly pleased

otherwise :/

The basic idea is that when the bullet collides with an object you'd send a containerRaycast through the object and find a suitable place on the other side to create a new bullet heading in the same direction as the original.

EDIT: If you don't feel like getting your hands dirty, it looks like Support_RaycastingWeapons allows piercing.
« Last Edit: April 23, 2015, 04:46:08 PM by Amade »

The idea is that you use a raycast and have it go until it hits an object.  I believe that you can then add a mask to the raycast to have it ignore that particular object and run the raycast again from the collision point.  Repeat until you have gone your preset distance.

Here's some rough pseudocode (with some exact function calls and syntax where more needed)

Code: [Select]
function firePenetratingBullet(penetratingTypes, intialDamage, damageLoss, numentrys, ignoreobject)
{
%ray = containerRayCast(muzzlePos, endPos, hitTypes, ignoreobject)
%pos =  posfromraycast(%ray)
spawn explosion at %pos

%obj =  objfromraycast(%ray)
if obj.getType() & $TypeMasks::PlayerObjectType
damage player

if (obj.getType() & penetratingTypes) && numentrys > 0
firePenetratingBullet(penetratingTypes, initialDamage * (1-damageLoss),  damageLoss, numentrys-1,%obj)
}

penetratingTypes defines what types the bullet will penetrate through
hitTypes defines what types the bullet will interact with; that is, be stopped by OR travel through
Both are a series a typemaks and bitwise or operators (ex: $TypeMasks::PlayerObjectType | $TypeMasks::FxBrickObjectType | $TypeMasks::VehicleObjectType will hit players, bricks, and vehicles)
ignoreobj should be the object firing the weapon (most likely the player)
« Last Edit: April 24, 2015, 05:03:18 PM by Headcrab Zombie »

You may want some edge case checks since anything that relies on plain geometry and has to deal with floating points can and will go wrong eventually (i.e. find its way into infinite recursion, in this case). Well, unless the projectile has a limit on how many times it can penetrate objects, of course, in which case you can essentially just rely on that running out (though you might still not want it to spawn several explosions in the same place).