Game Development Community

Projectile spreading

by gamer · in Torque Game Engine · 05/31/2006 (11:29 am) · 2 replies

Hi,is there some kind of weapon spreading already in the engine? I discovered this resource for projectile spreading http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1714, but I am wondering if something similar already exists in the engine since that resource is old.
thanks!

#1
05/31/2006 (11:51 am)
Nope. Also I don't like that resource because it doesn't account for vector changes when you look up or down, and it's not really a logical vector spread. It just gives you an initial offset of positions. Depending on what you are looking to do, there are resources that will actually offset the firing position for recoil "spread", but that's not useful for a shotgun or anything.

I use a much simpler method of just giving random offsets to the weapon's muzzle vector for my fire spreading. I have a couple stupid functions that are a bit needlessly complex, you could make it simpler than this. The point is just to add equal random +/- ranges to each of the vector components.
//Fake, cheap, and very effective vector scattering functions
//Recommended entry values for amount are 0-10
function ScatterVector(%vector, %amount){
return vectorAdd(%vector, ScatterAngle(%amount) SPC ScatterAngle(%amount) SPC ScatterAngle(%amount) );
}

//Support function for ScatterVector
function ScatterAngle(%angle){
%angle *= 100;   
return (getRandom(%angle * -1, %angle) / 10000);
}
So you just have those two functions in your code somewhere and in your weapon's onFire you call
%muzzleVector = ScatterVector(%obj.getMuzzleVector(%slot), 8);
Where the number is the amount of spread you want. I think I use 8 for the shotguns in my game.
#2
06/01/2006 (11:45 am)
Thank you, that is wonderful. I have also decided to use camera shake in combination with this.