need help spawning projectile

I’m currently working on a 2d game and my character has a gun. Im trying to spawn a bullet or projectile from the end of his gun. I’ve seen it done but can’t figure out how to do it. Does anyone know how to do this? Thanks for the help!

The first person template does this. The function you want is OnFire. It should look something like:

*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(GunOffset);

UWorld* const World = GetWorld();
if (World != NULL)
{
// spawn the projectile at the muzzle
World->SpawnActor<YourProjectileClassType>(ProjectileClass, SpawnLocation, SpawnRotation);
}
*
GunOffset is the position of the muzzle - this isnt an ideal way to do this of course. but you get the idea.

Related tutorials Unreal Engine 4 Tutorials - YouTube