diff --git a/Config/DefaultGame.ini b/Config/DefaultGame.ini index d6f6c04bb..745baa638 100644 --- a/Config/DefaultGame.ini +++ b/Config/DefaultGame.ini @@ -16,6 +16,8 @@ bIsDrawHitCursorLine=0 bIsDrawDeprojectedCursorLine=0 bIsShowMouseCursor=1 bIsDrawExplosionSpheres=0 +bIsDrawHitScan=0 +bIsPrintHitScanInfo=0 NetGraph=1 CameraVerticalSpeedLag=0.000000 UnUsedEnum=Everything diff --git a/Content/Maps/warmup.umap b/Content/Maps/warmup.umap index cc6628b50..a186998cc 100644 Binary files a/Content/Maps/warmup.umap and b/Content/Maps/warmup.umap differ diff --git a/Content/Maps/warmup/Mesh/_pbjZp0nv_hr_t_train_cratestack_train_cratestack_model.uasset b/Content/Maps/warmup/Mesh/_pbjZp0nv_hr_t_train_cratestack_train_cratestack_model.uasset index 1a3702a25..60d5f0b57 100644 Binary files a/Content/Maps/warmup/Mesh/_pbjZp0nv_hr_t_train_cratestack_train_cratestack_model.uasset and b/Content/Maps/warmup/Mesh/_pbjZp0nv_hr_t_train_cratestack_train_cratestack_model.uasset differ diff --git a/Source/Cloud9/Character/Cloud9Character.cpp b/Source/Cloud9/Character/Cloud9Character.cpp index daf57d36d..5223e3909 100644 --- a/Source/Cloud9/Character/Cloud9Character.cpp +++ b/Source/Cloud9/Character/Cloud9Character.cpp @@ -42,6 +42,7 @@ #include "Cloud9/Character/Components/Cloud9Inventory.h" #include "Cloud9/Character/Components/Cloud9SpringArmComponent.h" #include "Cloud9/Tools/Extensions/TContainer.h" +#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h" const FName ACloud9Character::SpringArmComponentName = TEXT("CameraBoom"); const FName ACloud9Character::CameraComponentName = TEXT("TopDownCamera"); diff --git a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp index 2ecd3f759..738278258 100644 --- a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp +++ b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp @@ -102,7 +102,19 @@ void UCloud9DeveloperSettings::InitializeCVars() RegisterConsoleVariable( bIsDrawExplosionSpheres, TEXT("r.bIsDrawExplosionSpheres"), - TEXT("Whether to debug explosions spheres") + TEXT("Whether to draw debug explosions spheres") + ); + + RegisterConsoleVariable( + bIsDrawHitScan, + TEXT("r.bIsDrawHitScan"), + TEXT("Whether to draw debug hit scan lines") + ); + + RegisterConsoleVariable( + bIsPrintHitScanInfo, + TEXT("r.bIsPrintHitScanInfo"), + TEXT("Whether to print hit scan info") ); RegisterConsoleVariable( diff --git a/Source/Cloud9/Game/Cloud9DeveloperSettings.h b/Source/Cloud9/Game/Cloud9DeveloperSettings.h index 2cf3f1de7..92ecece6f 100644 --- a/Source/Cloud9/Game/Cloud9DeveloperSettings.h +++ b/Source/Cloud9/Game/Cloud9DeveloperSettings.h @@ -70,6 +70,12 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) int32 bIsDrawExplosionSpheres; + UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) + int32 bIsDrawHitScan; + + UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) + int32 bIsPrintHitScanInfo; + UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) int32 NetGraph; diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index 47fd97bb8..516c3c979 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -32,6 +32,7 @@ #include "Cloud9/Tools/Extensions/FVector.h" #include "Cloud9/Game/Cloud9PlayerController.h" #include "Cloud9/Character/Cloud9Character.h" +#include "Cloud9/Game/Cloud9DeveloperSettings.h" #include "Cloud9/Weapon/Tables/WeaponTableFirearm.h" const FName ACloud9WeaponFirearm::TracerProbabilityParameterName = TEXT("Probability"); @@ -195,7 +196,7 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) if (not WeaponInfo->bIsFullAuto) { - WeaponState.ClearAction(EWeaponAction::PrimaryStart); + WeaponState.ClearAction(EWeaponAction::PrimaryLoop); } } else if (WeaponState.IsActionActive(EWeaponAction::PrimaryEnd)) @@ -240,49 +241,84 @@ bool ACloud9WeaponFirearm::Fire(const FFirearmWeaponInfo* WeaponInfo, const FFir return true; } + let Settings = UCloud9DeveloperSettings::Get(); + + var CollisionParams = FCollisionQueryParams::DefaultQueryParam; + + if (Settings->bIsDrawHitScan) + { + const FName TraceTag("HitScanTraceTag"); + GetWorld()->DebugDrawTraceTag = TraceTag; + CollisionParams.TraceTag = TraceTag; + CollisionParams.bTraceComplex = true; + } + let StartLocation = MuzzleFlash->GetComponentLocation(); - let EndLocation = CursorHit.Location; + // GetHitResultUnderCursor can return coordinates slightly upper then surface + // Prolong line in shoot direction + let EndLocation = FMath::Lerp(StartLocation, FVector{CursorHit.Location}, FirearmCommonData.LineTraceAlpha); FHitResult LineHit; - if (not GetWorld()->LineTraceSingleByChannel(LineHit, StartLocation, EndLocation, ECC_Visibility)) + let IsHit = GetWorld()->LineTraceSingleByChannel( + LineHit, + StartLocation, + EndLocation, + ECC_Visibility, + CollisionParams); + + if (Settings->bIsPrintHitScanInfo) { - log(Display, "LineTraceSingleByChannel not hit anything") - return true; + FString TargetName = IsHit ? *LineHit.Component->GetName() : TEXT("???"); + FString OwnerName = IsHit and LineHit.Component->GetOwner() != nullptr + ? *LineHit.Component->GetOwner()->GetName() + : TEXT("???"); + + log(Display, + "Target='%s' Owner='%s' Start={%s} End={%s} TraceEnd={%s} Hit={%s} ", + *TargetName, + *OwnerName, + *StartLocation.ToString(), + *EndLocation.ToString(), + *LineHit.TraceEnd.ToString(), + *LineHit.Location.ToString() + ); } - let Target = LineHit.Component; + if (IsHit) + { + let Target = LineHit.Component; - log(Verbose, "Target = %s Owner = %s", *Target->GetName(), *Target->GetOwner()->GetName()); + let Direction = LineHit.Location - StartLocation | EFVector::Normalize{}; - let Direction = LineHit.Location - StartLocation | EFVector::Normalize{}; + if (Target->IsSimulatingPhysics() and Target->Mobility == EComponentMobility::Movable) + { + let Velocity = WeaponInfo->Damage * FirearmCommonData.ImpulseMultiplier * Direction; + Target->AddImpulse(Velocity, NAME_None, true); + } - if (Target->IsSimulatingPhysics() and Target->Mobility == EComponentMobility::Movable) - { - let Velocity = WeaponInfo->Damage * FirearmCommonData.ImpulseMultiplier * Direction; - Target->AddImpulse(Velocity, NAME_None, true); - } + if (IsValid(FirearmCommonData.Tracer)) + { + let Tracer = UNiagaraFunctionLibrary::SpawnSystemAtLocation( + GetWorld(), + FirearmCommonData.Tracer, + StartLocation); + Tracer->SetVectorParameter(TracerDirectionParameterName, Direction); + Tracer->SetFloatParameter(TracerProbabilityParameterName, WeaponInfo->TracerProbability); + Tracer->SetAutoDestroy(true); + } - if (IsValid(FirearmCommonData.Tracer)) - { - let Tracer = UNiagaraFunctionLibrary::SpawnSystemAtLocation( - GetWorld(), - FirearmCommonData.Tracer, - StartLocation); - Tracer->SetVectorParameter(TracerDirectionParameterName, Direction); - Tracer->SetFloatParameter(TracerProbabilityParameterName, WeaponInfo->TracerProbability); - Tracer->SetAutoDestroy(true); - } + if (IsValid(FirearmCommonData.Squib)) + { + let Squib = UNiagaraFunctionLibrary::SpawnSystemAtLocation( + GetWorld(), + FirearmCommonData.Squib, + LineHit.Location, + CursorHit.Normal.Rotation()); + Squib->SetAutoDestroy(true); + } - if (IsValid(FirearmCommonData.Squib)) - { - let Squib = UNiagaraFunctionLibrary::SpawnSystemAtLocation( - GetWorld(), - FirearmCommonData.Squib, - LineHit.Location, - CursorHit.Normal.Rotation()); - Squib->SetAutoDestroy(true); + return true; } - return true; } diff --git a/Source/Cloud9/Weapon/Tables/WeaponCommonData.h b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h index 9bdb6d82d..40dd64093 100644 --- a/Source/Cloud9/Weapon/Tables/WeaponCommonData.h +++ b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h @@ -33,6 +33,14 @@ struct FFirearmCommonData UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Damage) float ImpulseMultiplier = 50.0f; + /** + * Alpha coefficient to fixup hit-scan registration. + * + * GetHitUnderCursor can return value slightly upper then surface. + */ + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Settings) + float LineTraceAlpha = 5.0f; + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Visual) float MagazineLifetime = 10.0f;