void ABaseCharacter::RequestFire()
{
ABaseCharacter* PlayerCharacter = Cast(GetWorld()->GetFirstPlayerController());
FVector CameraLocation;
FRotator CameraRotation;
FVector ViewLocation = GetWorld()->GetFirstPlayerController()->GetCharacter()->GetMesh()->GetSocketLocation(TEXT("ViewSocket"));
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(CameraLocation, CameraRotation);
FVector StartTrace = ViewLocation;
FVector EndTrace = ViewLocation + (CameraRotation.Vector() * 10000.0);
FHitResult HitResult(ForceInit);
FCollisionQueryParams TraceParams(FName(TEXT("WeaponTrace")), true, this);
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = true;
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace, ECC_Visibility, TraceParams))
{
DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor(255, 0, 0), true);
if (HitResult.GetActor())
{
UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *HitResult.GetActor()->GetName());
if (CurrentWeapon)
{
UE_LOG(LogTemp, Warning, TEXT("Used Weapon : %s"), *CurrentWeapon->GetName());
SendDamageRequest(HitResult.GetActor(), CurrentWeapon->GetWeaponDamage());
}
else {
UE_LOG(LogTemp, Warning, TEXT("CurrentWeapon NULL"));
}
}
else {
UE_LOG(LogTemp, Warning, TEXT("No Actor Found"))
}
}
else {
UE_LOG(LogTemp, Warning, TEXT("Did not Hit anything!"))
}
}
This is called when I press the Fire-button.