diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index d13e0306a..4776fae61 100644 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -137,6 +137,7 @@ DoubleClickTime=0.200000 +ActionMappings=(ActionName="Reload",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=R) +ActionMappings=(ActionName="Use",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E) +ActionMappings=(ActionName="Drop",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=G) ++ActionMappings=(ActionName="CursorSelfAim",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=V) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W) +AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S) +AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D) diff --git a/Content/Characters/Blueprints/BP_Cloud9Character.uasset b/Content/Characters/Blueprints/BP_Cloud9Character.uasset index 2185144d2..73baf88a8 100644 Binary files a/Content/Characters/Blueprints/BP_Cloud9Character.uasset and b/Content/Characters/Blueprints/BP_Cloud9Character.uasset differ diff --git a/Source/Cloud9/Character/Cloud9Character.cpp b/Source/Cloud9/Character/Cloud9Character.cpp index 7d5307a4e..57f44f8b3 100644 --- a/Source/Cloud9/Character/Cloud9Character.cpp +++ b/Source/Cloud9/Character/Cloud9Character.cpp @@ -124,58 +124,65 @@ void ACloud9Character::UnSneak() const } } -void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHitValid) +void ACloud9Character::SetViewDirection(const TOptional& HitResult) { - if (IsValid(CursorToWorld)) + if (HitResult) { - let ImpactNormal = HitResult.ImpactNormal; - let ImpactRotation = ImpactNormal.Rotation(); - - CursorToWorld->SetWorldLocation(HitResult.Location); - CursorToWorld->SetWorldRotation(ImpactRotation); - SetCursorIsHidden(false); - } - - let Settings = UCloud9DeveloperSettings::Get(); - - let StartLocation = GetMesh()->GetBoneLocation(CameraTargetBoneName, EBoneSpaces::WorldSpace); - - if (Settings->bIsDrawHitCursorLine) - { - DrawDebugLine( - GetWorld(), - StartLocation, - HitResult.Location, - FColor::Green, - false, - 0.0); - } - - if (Settings->bIsDrawDeprojectedCursorLine) - { - FVector WorldLocation; - FVector WorldDirection; - FVector2D MousePosition; - - GetCloud9Controller()->GetMousePosition(MousePosition.X, MousePosition.Y); - GetCloud9Controller()->DeprojectScreenPositionToWorld( - MousePosition.X, - MousePosition.Y, - WorldLocation, - WorldDirection); - - DrawDebugLine( - GetWorld(), - StartLocation, - WorldLocation, - FColor::Red, - false, - 0.0); - } - - if (bIsHitValid) - { - let TargetLocation = HitResult.Location; + if (IsValid(CursorToWorld)) + { + let ImpactNormal = HitResult->ImpactNormal; + let ImpactRotation = ImpactNormal.Rotation(); + + if (HitResult->GetActor() != this) + { + CursorToWorld->SetWorldLocation(HitResult->Location); + CursorToWorld->SetWorldRotation(ImpactRotation); + SetCursorIsHidden(false); + } + else + { + SetCursorIsHidden(true); + } + } + + let Settings = UCloud9DeveloperSettings::Get(); + + let StartLocation = GetMesh()->GetBoneLocation(CameraTargetBoneName, EBoneSpaces::WorldSpace); + + if (Settings->bIsDrawHitCursorLine) + { + DrawDebugLine( + GetWorld(), + StartLocation, + HitResult->Location, + FColor::Green, + false, + 0.0); + } + + if (Settings->bIsDrawDeprojectedCursorLine) + { + FVector WorldLocation; + FVector WorldDirection; + FVector2D MousePosition; + + GetCloud9Controller()->GetMousePosition(MousePosition.X, MousePosition.Y); + GetCloud9Controller()->DeprojectScreenPositionToWorld( + MousePosition.X, + MousePosition.Y, + WorldLocation, + WorldDirection); + + DrawDebugLine( + GetWorld(), + StartLocation, + WorldLocation, + FColor::Red, + false, + 0.0); + } + + let TargetLocation = HitResult->Location; let LookRotation = UKismetMathLibrary::FindLookAtRotation(StartLocation, TargetLocation); ViewVerticalRotation = LookRotation.Pitch; GetCloud9CharacterMovement()->Rotate({0.0f, LookRotation.Yaw, 0.0f}); diff --git a/Source/Cloud9/Character/Cloud9Character.h b/Source/Cloud9/Character/Cloud9Character.h index 4ed26a2d5..056a2226b 100644 --- a/Source/Cloud9/Character/Cloud9Character.h +++ b/Source/Cloud9/Character/Cloud9Character.h @@ -67,7 +67,7 @@ class ACloud9Character : public ACharacter void UnSneak() const; - void SetViewDirection(const FHitResult& HitResult, bool bIsHitValid); + void SetViewDirection(const TOptional& HitResult); UFUNCTION(BlueprintCallable) float GetViewVerticalRotation() const { return ViewVerticalRotation; } diff --git a/Source/Cloud9/Character/Structures/HealthConfig.h b/Source/Cloud9/Character/Structures/HealthConfig.h index 530d72c09..44bd558c5 100644 --- a/Source/Cloud9/Character/Structures/HealthConfig.h +++ b/Source/Cloud9/Character/Structures/HealthConfig.h @@ -10,7 +10,7 @@ struct FHealthConfig GENERATED_BODY() UPROPERTY(Category=Config, EditDefaultsOnly, BlueprintReadOnly, - meta=(UIMin="0", UIMax="20000.0", ClampMin="0", ClampMax="20000.0")) + meta=(UIMin="0", UIMax="999.0", ClampMin="0", ClampMax="999.0")) float Health = 100.0f; UPROPERTY(Category=Config, EditDefaultsOnly, BlueprintReadOnly, diff --git a/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp b/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp index 7cc0812c4..2b4b31ccc 100644 --- a/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp +++ b/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp @@ -25,6 +25,7 @@ #include "Cloud9KeyboardController.h" +#include "Cloud9/Game/Cloud9DeveloperSettings.h" #include "GameFramework/SpringArmComponent.h" #include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h" @@ -107,6 +108,12 @@ void UCloud9KeyboardController::OnReloadPressed() { WeaponAction([](let It) { It void UCloud9KeyboardController::OnReloadReleased() { WeaponAction([](let It) { It->Reload(true); }); } +void UCloud9KeyboardController::OnCursorSelfAim() +{ + static var Settings = UCloud9DeveloperSettings::Get(); + Settings->SetVariableValue(UCloud9DeveloperSettings::SelfAimEnabledName, not Settings->bIsSelfAimEnabled); +} + void UCloud9KeyboardController::OnUseAction() { if (let Pawn = GetCloud9Pawn(); IsValid(Pawn)) diff --git a/Source/Cloud9/Contollers/Cloud9KeyboardController.h b/Source/Cloud9/Contollers/Cloud9KeyboardController.h index ece074d8a..a1b047f71 100644 --- a/Source/Cloud9/Contollers/Cloud9KeyboardController.h +++ b/Source/Cloud9/Contollers/Cloud9KeyboardController.h @@ -77,6 +77,8 @@ class CLOUD9_API UCloud9KeyboardController void OnReloadPressed(); void OnReloadReleased(); + void OnCursorSelfAim(); + protected: float ForwardScale; float RightScale; diff --git a/Source/Cloud9/Contollers/Cloud9MouseController.cpp b/Source/Cloud9/Contollers/Cloud9MouseController.cpp index 75256e8bb..c29785fef 100644 --- a/Source/Cloud9/Contollers/Cloud9MouseController.cpp +++ b/Source/Cloud9/Contollers/Cloud9MouseController.cpp @@ -24,7 +24,9 @@ #include "Cloud9MouseController.h" #include "Cloud9/Tools/Cloud9ToolsLibrary.h" +#include "Cloud9/Tools/Extensions/APlayerController.h" #include "Cloud9/Contollers/Cloud9PlayerController.h" +#include "Cloud9/Game/Cloud9DeveloperSettings.h" UCloud9MouseController::UCloud9MouseController() { @@ -117,12 +119,14 @@ void UCloud9MouseController::ProcessCharacterView() const { if (let Controller = GetCloud9Controller(); IsValid(Controller)) { - FHitResult TraceHitResult; - let bIsHitValid = Controller->GetHitResultUnderCursor( + static var Settings = UCloud9DeveloperSettings::Get(); + let ActorsToIgnore = Settings->bIsSelfAimEnabled ? TArray{} : TArray{Pawn}; + let CursorHit = Controller | EAPlayerController::GetHitUnderCursor{ TRACE_CHANNEL, true, - TraceHitResult); - Pawn->SetViewDirection(TraceHitResult, bIsHitValid); + ActorsToIgnore + }; + Pawn->SetViewDirection(CursorHit); } } } diff --git a/Source/Cloud9/Contollers/Cloud9PlayerController.cpp b/Source/Cloud9/Contollers/Cloud9PlayerController.cpp index 0b09680d0..e7218eebc 100644 --- a/Source/Cloud9/Contollers/Cloud9PlayerController.cpp +++ b/Source/Cloud9/Contollers/Cloud9PlayerController.cpp @@ -101,6 +101,9 @@ void ACloud9PlayerController::SetupInputComponent() InputComponent->BindAction( "Use", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnUseAction); + InputComponent->BindAction( + "CursorSelfAim", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnCursorSelfAim); + KeyboardController->OnMoveDelegate.AddDynamic(MouseController, &UCloud9MouseController::OnCharacterMove); } diff --git a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp index b3af70a0d..511647812 100644 --- a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp +++ b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp @@ -26,6 +26,20 @@ #include "Cloud9/Tools/Extensions/FString.h" #include "Cloud9/Tools/Extensions/UObject.h" +FString UCloud9DeveloperSettings::ShowMouseCursorName = "r.ShowMouseCursor"; +FString UCloud9DeveloperSettings::DrawDeprojectedCursorLineName = "r.DrawDeprojectedCursorLine"; +FString UCloud9DeveloperSettings::DrawHitCursorLineName = "r.DrawHitCursorLine"; +FString UCloud9DeveloperSettings::DrawExplosionSphereName = "r.DrawExplosionSphere"; +FString UCloud9DeveloperSettings::DrawHitScanName = "r.DrawHitScan"; +FString UCloud9DeveloperSettings::PrintHitScanInfoName = "r.PrintHitScanInfo"; +FString UCloud9DeveloperSettings::NetGraphName = "r.NetGraph"; +FString UCloud9DeveloperSettings::AutoSelectWeaponName = "r.AutoSelectWeapon"; +FString UCloud9DeveloperSettings::InfiniteAmmoName = "r.InfiniteAmmo"; +FString UCloud9DeveloperSettings::CheatsName = "r.Cheats"; +FString UCloud9DeveloperSettings::SelfAimEnabledName = "r.SelfAimEnabled"; +FString UCloud9DeveloperSettings::CameraVerticalSpeedLagName = "r.CameraVerticalSpeedLag"; +FString UCloud9DeveloperSettings::VolumeName = "r.Volume"; + // ReSharper disable once CppPossiblyUninitializedMember UCloud9DeveloperSettings::UCloud9DeveloperSettings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -41,12 +55,13 @@ UCloud9DeveloperSettings::UCloud9DeveloperSettings(const FObjectInitializer& Obj bIsAutoSelectWeapon = 0; bIsInfiniteAmmo = 0; bIsCheatsEnabled = 0; + bIsSelfAimEnabled = 0; Volume = 0.1; } -const UCloud9DeveloperSettings* UCloud9DeveloperSettings::Get() +UCloud9DeveloperSettings* UCloud9DeveloperSettings::Get() { - static let Settings = StaticClass()->GetDefaultObject(); + static var Settings = StaticClass()->GetDefaultObject(); Settings->InitializeCVars(); return Settings; } @@ -57,14 +72,14 @@ void UCloud9DeveloperSettings::Save() log(Display, "%s", this | EUObject::Stringify{} | EFString::ToCStr{}); } -template -auto UCloud9DeveloperSettings::RegisterConsoleVariable(TValue& ValueRef, const TCHAR* Name, const TCHAR* Help) +template +auto UCloud9DeveloperSettings::RegisterConsoleVariable(ValueType& ValueRef, const TCHAR* Name, const TCHAR* Help) { static_assert( - TIsSame::Value || - TIsSame::Value || - TIsSame::Value || - TIsSame::Value, + TIsSame::Value || + TIsSame::Value || + TIsSame::Value || + TIsSame::Value, "TValue must be int, float, bool or FString" ); @@ -89,73 +104,79 @@ void UCloud9DeveloperSettings::InitializeCVars() RegisterConsoleVariable( bIsShowMouseCursor, - TEXT("r.IsShowMouseCursor"), + *ShowMouseCursorName, TEXT("Whether to draw line from character to GetHitResultUnderCursor point") ); RegisterConsoleVariable( bIsDrawDeprojectedCursorLine, - TEXT("r.IsDrawDeprojectedCursorLine"), + *DrawDeprojectedCursorLineName, TEXT("Whether to draw line from character to deprojected mouse cursor") ); RegisterConsoleVariable( bIsDrawHitCursorLine, - TEXT("r.bIsDrawHitCursorLine"), + *DrawHitCursorLineName, TEXT("Whether to show mouse cursor on screen or not in game") ); RegisterConsoleVariable( bIsDrawExplosionSpheres, - TEXT("r.bIsDrawExplosionSpheres"), + *DrawExplosionSphereName, TEXT("Whether to draw debug explosions spheres") ); RegisterConsoleVariable( bIsDrawHitScan, - TEXT("r.bIsDrawHitScan"), + *DrawHitScanName, TEXT("Whether to draw debug hit scan lines") ); RegisterConsoleVariable( bIsPrintHitScanInfo, - TEXT("r.bIsPrintHitScanInfo"), + *PrintHitScanInfoName, TEXT("Whether to print hit scan info") ); RegisterConsoleVariable( NetGraph, - TEXT("r.NetGraph"), + *NetGraphName, TEXT("Whether to show FPS and other specific debug info") ); RegisterConsoleVariable( bIsAutoSelectWeapon, - TEXT("r.AutoSelectWeapon"), + *AutoSelectWeaponName, TEXT("Select weapon after picking it up") ); RegisterConsoleVariable( bIsInfiniteAmmo, - TEXT("r.InfiniteAmmo"), + *InfiniteAmmoName, TEXT("Infinite Weapon Ammo") ); RegisterConsoleVariable( bIsCheatsEnabled, - TEXT("r.Cheats"), + *CheatsName, TEXT("Enable cheats") ); + RegisterConsoleVariable( + bIsSelfAimEnabled, + *SelfAimEnabledName, + TEXT("Enable self aim") + ); + RegisterConsoleVariable( CameraVerticalSpeedLag, - TEXT("r.CameraVerticalSpeedLag"), + *CameraVerticalSpeedLagName, TEXT("Configure how smoothly does the camera change its position vertically") ); RegisterConsoleVariable( Volume, - TEXT("r.Volume"), + *VolumeName, TEXT("Basic game volume") ); diff --git a/Source/Cloud9/Game/Cloud9DeveloperSettings.h b/Source/Cloud9/Game/Cloud9DeveloperSettings.h index f44ed22d8..f965b66ff 100644 --- a/Source/Cloud9/Game/Cloud9DeveloperSettings.h +++ b/Source/Cloud9/Game/Cloud9DeveloperSettings.h @@ -25,6 +25,8 @@ #include "CoreMinimal.h" +#include "Cloud9/Tools/Macro/Common.h" + #include "Cloud9DeveloperSettings.generated.h" USTRUCT(BlueprintType) @@ -54,6 +56,21 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings { GENERATED_UCLASS_BODY() +public: + static FString ShowMouseCursorName; + static FString DrawDeprojectedCursorLineName; + static FString DrawHitCursorLineName; + static FString DrawExplosionSphereName; + static FString DrawHitScanName; + static FString PrintHitScanInfoName; + static FString NetGraphName; + static FString AutoSelectWeaponName; + static FString InfiniteAmmoName; + static FString CheatsName; + static FString SelfAimEnabledName; + static FString CameraVerticalSpeedLagName; + static FString VolumeName; + public: // properties UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) int32 bIsDrawHitCursorLine; @@ -88,6 +105,9 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) int32 bIsCheatsEnabled; + UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Debug) + int32 bIsSelfAimEnabled; + UPROPERTY(config, EditAnywhere, BlueprintReadWrite, Category=Sound) float Volume; @@ -99,12 +119,28 @@ class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings public: // static functions UFUNCTION(BlueprintCallable, Category=Settings, DisplayName=GetCloud9DeveloperSettings) - static const UCloud9DeveloperSettings* Get(); + static UCloud9DeveloperSettings* Get(); public: // functions UFUNCTION(BlueprintCallable) void Save(); + template + void SetVariableValue(const FString& Name, ValueType Value) + { + static_assert( + TIsSame::Value || + TIsSame::Value || + TIsSame::Value || + TIsSame::Value, + "TValue must be int, float, bool or FString" + ); + + let ConsoleManager = &IConsoleManager::Get(); + var Variable = ConsoleManager->FindConsoleVariable(*Name); + Variable->Set(Value); + } + #if WITH_EDITOR virtual void PostInitProperties() override; virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; diff --git a/Source/Cloud9/Tools/Extensions/APlayerController.h b/Source/Cloud9/Tools/Extensions/APlayerController.h new file mode 100644 index 000000000..58c2119d8 --- /dev/null +++ b/Source/Cloud9/Tools/Extensions/APlayerController.h @@ -0,0 +1,43 @@ +// Copyright (c) 2024 Alexei Gladkikh + +#pragma once + +#include "Cloud9/Tools/Macro/Common.h" +#include "Cloud9/Tools/Macro/Logging.h" +#include "Cloud9/Tools/Macro/Operator.h" + +namespace EAPlayerController +{ + struct GetHitUnderCursor + { + ECollisionChannel TraceChannel; + bool bTraceComplex; + const TArray& ActorsToIgnore{}; + + TOptional operator()(const APlayerController* Self) const + { + assertf(Self != nullptr, "APlayerController should not be nullptr"); + + let LocalPlayer = Cast(Self->Player); + if (IsValid(LocalPlayer) and LocalPlayer->ViewportClient) + { + FVector2D MousePosition; + if (LocalPlayer->ViewportClient->GetMousePosition(MousePosition)) + { + FHitResult HitResult; + FCollisionQueryParams Params; + Params.bTraceComplex = bTraceComplex; + Params.AddIgnoredActors(ActorsToIgnore); + if (Self->GetHitResultAtScreenPosition(MousePosition, TraceChannel, Params, HitResult)) + { + return HitResult; + } + } + } + + return {}; + } + + OPERATOR_BODY(GetHitUnderCursor) + }; +} diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index c80d3ad10..7951ef508 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -33,6 +33,7 @@ #include "Cloud9/Contollers/Cloud9PlayerController.h" #include "Cloud9/Character/Cloud9Character.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" +#include "Cloud9/Tools/Extensions/APlayerController.h" #include "Cloud9/Weapon/Sounds/Cloud9SoundPlayer.h" #include "Cloud9/Weapon/Tables/WeaponTableFirearm.h" #include "Kismet/GameplayStatics.h" @@ -306,11 +307,36 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire( EjectCase(); - FHitResult CursorHit; - if (not Controller->GetHitResultUnderCursor(TRACE_CHANNEL, true, CursorHit)) + // When we do line hit scan ignore our character in any case (Enabled or not SelfAimOption) + let ActorsToIgnore = TArray{Character}; + + let StartLocation = MuzzleFlash->GetComponentLocation(); + + FVector EndLocation; + if (not Settings->bIsSelfAimEnabled) { - log(Error, "Cursor not hit anything") - return EFirearmFireStatus::Success; + TOptional CursorHit = Controller | EAPlayerController::GetHitUnderCursor{ + TRACE_CHANNEL, + true, + ActorsToIgnore + }; + + if (not CursorHit) + { + log(Error, "Cursor not hit anything") + return EFirearmFireStatus::Success; + } + + // GetHitResultUnderCursor can return coordinates slightly upper then surface + // Prolong line in shoot direction + EndLocation = FMath::Lerp(StartLocation, FVector{CursorHit->Location}, FirearmCommonData.LineTraceAlpha); + } + else + { + EndLocation = FMath::Lerp( + StartLocation, + StartLocation + MuzzleFlash->GetForwardVector(), + FirearmCommonData.UnknownTraceAlpha); } var CollisionParams = FCollisionQueryParams::DefaultQueryParam; @@ -321,13 +347,9 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire( GetWorld()->DebugDrawTraceTag = TraceTag; CollisionParams.TraceTag = TraceTag; CollisionParams.bTraceComplex = true; + CollisionParams.AddIgnoredActors(ActorsToIgnore); } - let StartLocation = MuzzleFlash->GetComponentLocation(); - // 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; let IsHit = GetWorld()->LineTraceSingleByChannel( LineHit, @@ -377,13 +399,14 @@ EFirearmFireStatus ACloud9WeaponFirearm::Fire( Tracer->SetAutoDestroy(true); } + // TODO: Move Squibs to other asset if (IsValid(FirearmCommonData.Squib)) { let Squib = UNiagaraFunctionLibrary::SpawnSystemAtLocation( GetWorld(), FirearmCommonData.Squib, LineHit.Location, - CursorHit.Normal.Rotation()); + LineHit.Normal.Rotation()); Squib->SetAutoDestroy(true); } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp index d87494fb5..bfba02b27 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp @@ -26,6 +26,7 @@ #include "DrawDebugHelpers.h" #include "PhysicsEngine/RadialForceComponent.h" +#include "Cloud9/Tools/Extensions/APlayerController.h" #include "Cloud9/Tools/Extensions/TVariant.h" #include "Cloud9/Character/Cloud9Character.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" @@ -386,8 +387,14 @@ bool ACloud9WeaponGrenade::Throw() const return false; } - FHitResult CursorHit; - if (not Controller->GetHitResultUnderCursor(TRACE_CHANNEL, true, CursorHit)) + let ActorsToIgnore = TArray{Character}; + let CursorHit = Controller | EAPlayerController::GetHitUnderCursor{ + TRACE_CHANNEL, + true, + ActorsToIgnore + }; + + if (not CursorHit) { log(Error, "[Weapon='%s'] Cursor not hit anything", *GetName()); return false; @@ -405,7 +412,7 @@ bool ACloud9WeaponGrenade::Throw() const let CommonData = WeaponDefinition.GetCommonData(); Inventory->DropWeapon( GetWeaponSlot(), - CursorHit.Location, + CursorHit->Location, CommonData->Grenade.MaxThrowAngle, CommonData->Grenade.MaxThrowImpulse); diff --git a/Source/Cloud9/Weapon/Tables/WeaponCommonData.h b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h index e272633d9..6212687c0 100644 --- a/Source/Cloud9/Weapon/Tables/WeaponCommonData.h +++ b/Source/Cloud9/Weapon/Tables/WeaponCommonData.h @@ -43,6 +43,12 @@ struct FFirearmCommonData UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Settings) float LineTraceAlpha = 5.0f; + /** + * If have no end location for aiming then just trace by forward vector using this alpha + */ + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Settings) + float UnknownTraceAlpha = 1000.0f; + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Visual) float MagazineLifetime = 10.0f;