Game Development Community

Need Help - Firing a projectile weapon in a "spread" pattern

by Nicolai Dutka · in Torque Game Engine Advanced · 09/30/2008 (9:48 pm) · 2 replies

I am trying to make a special shot that splits going in a "crows feet" pattern. I can't figure out how to get consistant angles. To make it easy on you, we don't have to deal with up/down angles. That is to say, the player is set to always be facing perfectly straight ahead (I disabled the ability to look up and down) so now we are just dealing with altering the angle of the projectile by a tiny bit to the left and right to make bullets 2 and 3.

function weap::onFire( %this, %obj, %slot )
{
        %projectile = %this.projectile;

        %muzzleVector   =  %obj.getMuzzleVector( %slot );

I am guessing this is the spot I need to work with. I tried to echo out the %muzzleVector at this point and I seem to be getting some good numbers to work with, but I don't know what to do with them. I tried VectorAdd, VectorCross, VectorDot using %muzzleVector and "0.2 0.2 0" but the results have been widely varied. The only one that was even close to what I wanted was the "vectorAdd" but when %muzzleVector is near 1 or -1, it has far less effect than when it is closer to 0.5 and -0.5. (At which point I do get a fairly decent spread), but at 1 and -1, all three bullets would stream together...

I can't figure out how to do it. Anyone?

#1
10/10/2008 (3:26 pm)
I still can't figure this one out... anyone?
#2
10/10/2008 (6:31 pm)
Have a look at the shotgun/accuracy matrix resource.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1714

With a bit of rejigging you might be able to work something out, or at least better understand how to create an accuracy matrix.

Word of warning:
//%x = up
//%y = down
//%z = left and right
So obviously you'd want to swap x and y for z so you'd have full horizontal instead of vertical control (don't ask me how I don't know!). Then it'd be a case of
OnFire - create left angle matrix - spawn bullet - create right angle matrix - spawn second bullet.

That's a theory anyhow.