[Solved]How to make shotgun instant hit spread

Was looking at the shooterweapon_instanthit. I am trying to grasp the logic of how to make it be able to produce a shotgun effect using multiple traces like a scatter shot. Any help in the right direction if I am not even looking in the right area is appreciated.

I was thinking that it would be possible to have it send out multiple traces at randomdirections like it does when you fire without aiming using the CurrentFiringSpread. either all at the same time or fire them off very fast consecutively.

heres the existing code I am examining

void AShooterWeapon_Instant::FireWeapon()
{
	const int32 RandomSeed = FMath::Rand();
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = GetCurrentSpread();
	const float ConeHalfAngle = FMath::DegreesToRadians(CurrentSpread * 0.5f);

	const FVector AimDir = GetAdjustedAim();
	const FVector StartTrace = GetCameraDamageStartLocation(AimDir);
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, ConeHalfAngle, ConeHalfAngle);
	const FVector EndTrace = StartTrace + ShootDir * InstantConfig.WeaponRange;

	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);

	CurrentFiringSpread = FMath::Min(InstantConfig.FiringSpreadMax, CurrentFiringSpread + InstantConfig.FiringSpreadIncrement);
}

You seem to have the right code, what exactly is your problem?

Rama

ok well that’s good to know that I am on the right trail. I am stuck in execution I am not sure how to make it where I could fire off the trace in the way I explained.

Sorry I just don’t know enough in this area of what is going on and I really do not want to try to write something from scratch.

I just need help as I am sure it should be something simple to implement a variable to execute the code properly to make a multi-trace function or do I need to write a function to call on this one several times?

or do I need to write a function to
call on this one several times?

for starters you could do

for(int32 EmileItr = 0; EmileItr < 30; EmileItr++ )
{
    FireWeapon();
}

that will fire the weapon 30 times instantly, in a random cone-shaped pattern, according to Epic’s supplied code :slight_smile:

Rama

PS: if you want a wider spread, experiment and look at this part

const float CurrentSpread = GetCurrentSpread();

PSS: if this resolves your issue please check mark my answer so Epic knows this matter is under control.

Rama as always you are colorful and under control thanks for your help I did already notice the spread and other functions.

I think I even understood them because they were just doing math and I could trace that easily enough.

Again this will fill in a lot of gaps I will see if I can achieve the effect I want

“Rama as always you are colorful and under control thanks for your help”

Hee hee!

Glad I could help out!

:slight_smile:

Rama