I’m trying to make consistent (and circular) bullet spread, however when i aim upwards the bullets no longer deviate in the yaw axis anymore.
The system first randomly calculates an amount to miss by, and an angle to miss in(polar co-ordinate based so the spread is circular), it then converts that into an FRotator (in the Pitch and Yaw axis) and adds this to the Spawn Rotation to determine the end point of the debug line draw, Ive also included a debug sphere draw to clearly demonstrate how the spread amount changes as the aim pitch changes
So here’s my code:
float Spread; //Picks a random amount to miss by
Spread = Fire1SpreadMin + FMath::FRand() * Fire1SpreadMax; //SpreadMin is for donut shaped pattern
float SpreadAngle; //Picks an Angle Perpendicular to the firing direction to spread
SpreadAngle = FMath::FRand() * 360.0f;
//Combines these into a Rotator Vector to add to the Spawn Rotation.
FRotator RandAngle;
RandAngle.Yaw = YawSM * Spread * FMath::Sin(SpreadAngle);
RandAngle.Pitch = PitchSM * Spread * FMath::Cos(SpreadAngle);
//Debug line Projectile Trajectory
uint8 col;
col = rand() * 255;
DrawDebugLine( World,
SpawnLocation,
SpawnLocation + (100000.0f * (SpawnRotation + RandAngle).Vector()),
FColor(255, 255, 0), //Yellow
false, //Persistent?
0.0f, //Lifetime
0, //Depth Priority
0.0f); //Line Width
DrawDebugSphere(World,
SpawnLocation + (5000.0f * (SpawnRotation + RandAngle).Vector()),
50.0f,//Radius
4, //Segments
FColor(255, 0, 0),
false, //Persistent
10.0f, //Duration
0, //Depth Priority
0.0f); //Width
Here are some pictures to illustrate my problem
Aiming Horizontally
Aiming Diagonally
Aiming Vertically
So how can i get the spread to be independent of the angle the player is aiming?