How would I go about creating specific shotgun spread patterns? In terms of calculating the projectile spawn rotation. I know how to create a shotgun spread, but the rotations are all random. I want to be able to give it specific shapes like the spread patterns of the Peacekeeper from Apex Legends.
I don’t know where to start or what I’m exactly looking for in terms of math. Any tips in terms of where I should be looking would be appreciated.
This is my current code:
for (int projectile = 0; projectile < IShotgunEnergyAmount; projectile++)
{
FTransform NewSPawnRotation(SpawnRotation);
NewSPawnRotation.ConcatenateRotation(FRotator(FMath::FRandRange(-0.1f, 0.1f) * (FShotgunEnergySpread), (FMath::FRandRange(-0.1f, 0.1f) * (FShotgunEnergySpread)), 0).Quaternion());
NewSPawnRotation.NormalizeRotation();
AWeaponSystemProjectile* p = World->SpawnActor<AWeaponSystemProjectile>(ProjectileClass, SpawnPoint, NewSPawnRotation.Rotator(), ActorSpawnParams);
}
I can’t wrap my head around on how I would go away from the random spread and move towards a set pattern. Here are some examples of patterns taken from Apex Legends:
Edit.
I’ve been thinking about how to approach this. I dunno if this would make any sense, but here are my thoughts on how I could code the first spread:
for( int p = 0, p < a, p++)
{
if( p = 0)
{
spawn(0/0);
}
else
{
spawn(0/p*0.5);
spawn(p*0.5/p*0.5);
spawn(p*0.5/-(p*0.5));
spawn(-(p*0.5)/-(p*0.5);
spawn(-(p*0.5)/(p*0.5);
}
}
Is there a more elegant way of doing this?