From 64420326c085262fe9c17c5f690ff3ed0e49134c Mon Sep 17 00:00:00 2001 From: Rafal Swierczek <34179rs@gmail.com> Date: Wed, 11 Oct 2023 15:20:18 +0100 Subject: [PATCH] Implemented Input for Interacting --- .../BountySystem/BountyDirector.uasset | 4 ++-- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 ++-- .../Input/Actions/IA_Interact.uasset | 3 +++ .../FirstPerson/Input/IMC_Default.uasset | 4 ++-- .../EndlessVendettaCharacter.cpp | 23 +++++++++++++++++++ .../EndlessVendettaCharacter.h | 6 +++++ 6 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Interact.uasset diff --git a/EndlessVendetta/Content/BountySystem/BountyDirector.uasset b/EndlessVendetta/Content/BountySystem/BountyDirector.uasset index 0acba18f..0c495524 100644 --- a/EndlessVendetta/Content/BountySystem/BountyDirector.uasset +++ b/EndlessVendetta/Content/BountySystem/BountyDirector.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d9d96d19206de2c336790632a9774519478154bb0eedd7080b8ee8c485e15844 -size 43857 +oid sha256:b32ceb2fef229808e1ce4cb7ed0542b84e6e0b0e6b93e7a6d0bcd7bdeea57895 +size 18290 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index e7dcb857..36dc8b7e 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65d9f1286e3e2a0afeb00fd61e2a4ad5d105f8c4ea61cf146761901c810ea4bb -size 42451 +oid sha256:43fc07df656cbeca06e4be24c733f74347f92cf868f0197227f924c697e7b984 +size 42671 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Interact.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Interact.uasset new file mode 100644 index 00000000..ef199a6b --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Interact.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56e5fddda3b901b313fde855f6615339551cedbc06032712cda370c384bab101 +size 1370 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index 2bc21ec7..6f9680cf 100644 --- a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset +++ b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e84853e2ab5cb8653ef3686fdd8ce458fbadd1261807bdc73feb5212015290ce -size 17496 +oid sha256:574a8a6fe6bd0d9ee1e4e32e2fadfbaea00a337525907ac14aba3dd4bef1b164 +size 18076 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index d27bdc42..522245e6 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -6,6 +6,7 @@ #include "Components/CapsuleComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "InteractableActor.h" #include "AI/EnemyCharacter.h" #include "GameFramework/CharacterMovementComponent.h" #include "Kismet/GameplayStatics.h" @@ -102,9 +103,31 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* //Crouching EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::SetCrouch); EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::SetUnCrouch); + + //Interacting + EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::Interact); } } +void AEndlessVendettaCharacter::Interact() +{ + FHitResult OutHit; + FCollisionQueryParams QueryParams = FCollisionQueryParams::DefaultQueryParam; + QueryParams.AddIgnoredActor(this); + FVector LT_Start = FirstPersonCameraComponent->GetComponentLocation(); + FVector LT_End = LT_Start + (FirstPersonCameraComponent->GetForwardVector() * InteractionRange); + DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Red, false, 3, 0, 2); + if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams)) return; + + AActor* HitActor = OutHit.GetActor(); + AInteractableActor* InteractableActor = Cast(HitActor); + if (!IsValid(InteractableActor)) return; + + DrawDebugLine(GetWorld(), LT_Start, OutHit.ImpactPoint, FColor::Green, false, 3, 0, 2); + InteractableActor->Interact(); +} + + void AEndlessVendettaCharacter::SetCrouch() { Crouch(); diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index b1c84ec7..cc936f99 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -68,6 +68,9 @@ class AEndlessVendettaCharacter : public ACharacter UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) UInputAction* CrouchAction; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) + UInputAction* InteractAction; + public: AEndlessVendettaCharacter(); @@ -146,6 +149,9 @@ protected: void EquipPrimary(); void EquipSecondary(); + UPROPERTY(EditDefaultsOnly, Category = "Interaction") + float InteractionRange = 250; + void Interact(); protected: // APawn interface