Hey all, I just switched over to giving Unreal Engine a shot after spending the last year and a bit working with Unity and I’m having an issue with trying to modify the FPS Template to add things like bullet spread.
The issue I’ve been having has been that whenever I try to aim up or down my projectile spread flattens out and I’m unable to figure out why.
I’m modifying the OnFire class and applying a simple range offset to both Pitch and Yaw
void ATriggerCharacter::OnFire()
{
// try and fire a projectile
if (ProjectileClass != NULL)
{
UWorld* const World = GetWorld();
if (World != NULL)
{
for (int i = 0; i < NumberOfProjectiles; i++) {
const FRotator SpawnRotation = GetControlRotation();
// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
const FVector SpawnLocation = ((FP_MuzzleLocation != nullptr) ? FP_MuzzleLocation->GetComponentLocation() : GetActorLocation()) + SpawnRotation.RotateVector(GunOffset);
FRotator NewSpawnRotation = FRotator(GetControlRotation().Pitch + FMath::FRandRange(-0.1f, 0.1f) * (100.0f - ProjectileAccuracy),
GetControlRotation().Yaw + FMath::FRandRange(-0.1f, 0.1f) * (100.0f - ProjectileAccuracy),
GetControlRotation().Roll);
DrawDebugLine(World, SpawnLocation, SpawnLocation + NewSpawnRotation.RotateVector(FVector(10000.0f, 0.0f, 0.0f)), FColor::Black, false, 60.0f, (uint8)'\000', 0.5f);
// spawn the projectile at the muzzle
World->SpawnActor<ATriggerProjectile>(ProjectileClass, SpawnLocation, NewSpawnRotation);
}
}
}
As far as I can tell, the spread shouldn’t be flattening out, When I take the range of the applied offset of all projectiles spawned per shot, the range remains fairly constant whether I’m shooting forward or straight up and I cannot figure out why it’s doing this, does anyone have any thoughts?