Projectile not firing in the right direction

I’m making a top down kinda isometric game and I’m trying to have the player fire projectiles. I’m making the player and the gun separate actors. The player class attaches the gun to a bone socket and then tells it when to fire.The issue is that it’s not firing in the direction the player is facing. Here is the firing code:

UWorld* const World = GetWorld();
	if (bFiring && FireCoolDownTimer < World->GetTimeSeconds())
			if (World)

				if (ProjectileClass != NULL)
					// Get the positions transforms
					// Get the camera transform
					FVector Loc = GetActorLocation();
					FRotator Rot = GetAttachParentActor()->GetActorRotation();
					FVector const MuzzleLocation = Loc + MuzzleOffset;  

					FActorSpawnParameters SpawnParams;
					SpawnParams.Owner = this;
					SpawnParams.Instigator = Instigator;
					// spawn the projectile at the muzzle
					AProjectile* const Projectile = World->SpawnActor<AProjectile>(ProjectileClass, MuzzleLocation, Rot, SpawnParams);
					if (Projectile)
						FVector const LaunchDir = Rot.Vector();

				}//projectile check end
		}//world check end
			FireCoolDownTimer = World->GetTimeSeconds() + FireCoolDown;
	}//bfiring check end

The “InitVelocity” code is:

void AProjectile::InitVelocity(const FVector& ShootDirection)
	if (ProjectileMovement)
		// set the projectile's velocity to the desired direction
		ProjectileMovement->Velocity = ShootDirection * ProjectileMovement->InitialSpeed;

I think getting the forward vector might be what you are looking for.

That didn’t help I still have the same result of the projectile being fired in the same direction

check your BP/projectile class and make sure ‘Projectile Movement.Initial velocity in local space’ property is false.

I know that you have to have the rotation set to world instead of local. Our programmer was having the exact same problem.

For some reason having local rotation makes it go in random directions.

Turning that on seems to have no effect as well.

It should be turned off, and looks like you also need normalize vector you get from FRotator.

How do you transform a rotation vector into world space?

What object is the attached parent?

You should be firing along the local x axis. I dont think you want to shoot relative to the world.

Make sure that the x axis of the parent lines up with x axis of the gun.

Something else you could try that’s a bit of a hack is you can calculate the look at rotation between your projectile and the character (use this UKismetMathLibrary::FindLookAtRotation) and subtract 180 on the x.

I have no idea how he did it… I just know that this fixed his problem.

I have made it so that this code now executes inside of the Player class I have also changed this line to fire across the X axis but it is still firing on the world space X axis

FVector const LaunchDir = FTransform(Rotation).GetScaledAxis(EAxis::X);


I fixed the issue, the tutorial is retarded or something…