Author Topic: Projectiles ignoring bricks and such?  (Read 1610 times)

Is there a way that one could make a projectile that would go through a brick or .dts shape but still damage players that it goes through?

No, the projectile collision mask is set in the engine. However some dumbass is going to come along and suggest doing a radius search for each brick every millisecond to detect incoming projectiles and then decollision itself. To whoever was planning to do this: Just no.

You could save the vector the bullet was shot at and then reshoot it from the bricks collision when one hits a brick.

Well, you could do a radius search every milisecond to detect incoming projectiles and then decollision itself. Might work.

Use a tick every ten/hundred milliseconds to do a raycast for the objects you want it to hit in the bullet's fire vector/speed. If it hits something, react appropriately. If it doesn't, store the "end" position of the bullet as the one to use as the start for the next object. This probably won't work for weapons with an actual bullet shape (particles would work, though) or ballistic weapons easily.

Note that 'real' projectiles in Torque do actually use similar raycasts every few milliseconds to work, it's just that they use engine code rather than scripts to be more efficient.

We hardly need more of these crappy loop-based add-ons.

Why not just have the bullet cause a high level of brick damage and make it shoot out 2 bullets instead of one when you click the fire button? That way the first bullet will destroy the brick in the way, and the second will kill the target.

Well, you could do a radius search every milisecond to detect incoming projectiles and then decollision itself. Might work.
Oo i like that idea

Why not just have the bullet cause a high level of brick damage and make it shoot out 2 bullets instead of one when you click the fire button? That way the first bullet will destroy the brick in the way, and the second will kill the target.
Yeah, I think that is probabl what I am going to have to go with.

What if there are two bricks in the way...

Well I was probably going to do three shots each doing 34 damage. That way if it is a direct shot then it is a one-hit kill but if it goes through objects it would do less damage. I don't want it to continue on forever, I just want to be able to headshot someone through a wall. :P

My idea wasn't crappy & loop based :o (I was serious >.>, I've gotten it to work before)


The only problem is that the projectiles lifespan is reset, thus it goes on for really long amounts of time.(could be stopped by storing how many bricks its hit and stopping it at _ amount, I guess)

It also has the advantage of not being lagged down by using 3 projectiles for one shot, and it works without brick damage on.

Actually that is a good idea too. You could have the one that is initially shot to be the one that get the vector and then that spawns another that just kills normally. Or whatever. But how do you get the vectors and stuff on collision?

In order to grab the vector you will need to get it onfiring and attach it to the projectile like so
Code: [Select]
function <weaponimage>::onFire(%this,%obj,%slot)
{
%obj.playthread(2, shiftaway);
//comment following line out to get rid of recoil
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-1")));
%projectile = "<yourprojectile>";
%spread = 0.0000;

%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
%p.vectorshotat=%velocity;

return %p;
}

function <weaponprojectile>::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(strlwr(%col.getclassname()) $= "fxdtsbrick"){
%projectile = "<yourprojectile>";
%spread = 0.0000;

%velocity = %this.vectorshotat;
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %this.getposition();
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
%p.vectorshotat=%velocity;

return %p;
}

parent::oncollision(%this,%obj,%col,%fade,%pos,%normal);
}

Untested but that should do whatever you need.
« Last Edit: July 13, 2008, 07:05:16 PM by rkynick »

Uh no. Looks like you just jacked the projectile spread resource then set the spread to 0. I guess you don't have a very strong knowledge of vectors.

Secondly, If a bullet enters the corner of a brick this is going to alter its trajectory completely. For example:

I think you'll need some more serious maths than this to make this solution work.

Edit: Sorry, looks like you just jacked it out of the Shotgun add-on. You even left the recoil line in there? Just for your information, all of that isn't necessary to create a projectile.