I do not know much English, so I use a translator from google.
Why my code is not working properly?
void ACustomCharacter::FireTimer() {
if(ProjectileClass != NULL) {
const FRotator SpawnRotation = FirstPersonMesh->GetSocketRotation(TEXT("projectile_shot"));
const FVector SpawnLocation = FirstPersonMesh->GetSocketLocation(TEXT("projectile_shot"));
FHitResult hitResult;
FCollisionQueryParams collisionParams;
const FVector currentLocation = CameraComponent->GetComponentLocation();
const FVector futureLocation = currentLocation + FVector(10000.0f, 0.0f, 0.0f);
if(ActorLineTraceSingle(hitResult, currentLocation, futureLocation, ECC_WorldStatic, collisionParams)) {
FVector Forward = (currentLocation - hitResult.TraceEnd);
FRotator Rot = FRotationMatrix::MakeFromX(Forward).Rotator();
UWorld* const World = GetWorld();
if(World != NULL) {
World->SpawnActor<AShellBoom>(ProjectileClass, SpawnLocation, Rot);
}
}
}
}