I was trying to make a FPS Shooter in C++ from scratch based on the template, but for some reason when i run the game the projectile keeps spawning at the same location.
Here is my Spawning Code:
void AFPSCharacter::OnFire()
{
// try and fire a projectile
if (ProjectileClass != NULL)
{
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 = GetActorLocation() + SpawnRotation.RotateVector(MuzzleOffset);
UWorld* const World = GetWorld();
if (World != NULL)
{
// spawn the projectile at the muzzle
AFPSProjectile* Projectile = World->SpawnActor<AFPSProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
if (Projectile)
{
// find launch direction
FVector const LaunchDir = SpawnRotation.Vector();
Projectile->InitVelocity(LaunchDir);
}
}
}
}
i have tested with a print to give me the value of SpawnLocation and this is what it prints:
It shows the multiple locations where they should be spawning, bue instead they all spawn at the starting location.