// Fill out your copyright notice in the Description page of Project Settings. #include "ProjectileWeapon.h" #include "Projectile.h" #include "Engine/SkeletalMeshSocket.h" void AProjectileWeapon::Fire(const FVector& HitTarget) { Super::Fire(HitTarget); if (!HasAuthority()) return; APawn* InstigatorPawn = Cast(GetOwner()); const USkeletalMeshSocket* MuzzleFlashSocket = GetWeaponMesh()->GetSocketByName(FName("MuzzleFlash")); if (MuzzleFlashSocket) { FTransform SocketTransform = MuzzleFlashSocket->GetSocketTransform(GetWeaponMesh()); // From muzzle flash socket to hit location from TraceUnderCrosshairs FVector ToTarget = HitTarget - SocketTransform.GetLocation(); FRotator TargetRotation = ToTarget.Rotation(); if (ProjectileClass && InstigatorPawn) { FActorSpawnParameters SpawnParams; SpawnParams.Owner = GetOwner(); SpawnParams.Instigator = InstigatorPawn; UWorld* World = GetWorld(); if (World) { World->SpawnActor( ProjectileClass, SocketTransform.GetLocation(), TargetRotation, SpawnParams ); } } } }