Issue Modifying the FPS Template for Physical Projectile Spread

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),

				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?

That NewSpawnRotation.RotateVector() looks out of place to me.
I’m used to doing NewSpawnRotation.Vector().GetSafeNormal() * 10000 or similar.

The rotate vectors just look out of place to me in general :slight_smile:

Are you talking about the NewSpawnRotation.RotateVector in the DebugLine call? I’m not having an issue with that, the debug lines follow the path of the projectiles perfectly. It’s the flattening of the projectiles along one axis as I move my aim up or down that I’m having trouble figuring out.

Sorry for the double post, my previous post wasn’t approved yet.

After some messing around, I’m still confused but it seems like the Pitch of my character is dampening or in some other way affecting the Yaw rotation of the projectiles after I fire them. Given all the debug output I’ve been creating, the offset range from the original rotation for all spawned projectiles are remaining the same no matter which angle I fire the projectiles so I’m having a tough time figuring this out.