Implemented Input for Interacting

This commit is contained in:
Rafal Swierczek 2023-10-11 15:20:18 +01:00
parent be22eae329
commit 64420326c0
6 changed files with 38 additions and 6 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:d9d96d19206de2c336790632a9774519478154bb0eedd7080b8ee8c485e15844 oid sha256:b32ceb2fef229808e1ce4cb7ed0542b84e6e0b0e6b93e7a6d0bcd7bdeea57895
size 43857 size 18290

Binary file not shown.

Binary file not shown.

View File

@ -6,6 +6,7 @@
#include "Components/CapsuleComponent.h" #include "Components/CapsuleComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
#include "InteractableActor.h"
#include "AI/EnemyCharacter.h" #include "AI/EnemyCharacter.h"
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
@ -102,9 +103,31 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent*
//Crouching //Crouching
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::SetCrouch); EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::SetCrouch);
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::SetUnCrouch); 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<AInteractableActor>(HitActor);
if (!IsValid(InteractableActor)) return;
DrawDebugLine(GetWorld(), LT_Start, OutHit.ImpactPoint, FColor::Green, false, 3, 0, 2);
InteractableActor->Interact();
}
void AEndlessVendettaCharacter::SetCrouch() void AEndlessVendettaCharacter::SetCrouch()
{ {
Crouch(); Crouch();

View File

@ -68,6 +68,9 @@ class AEndlessVendettaCharacter : public ACharacter
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* CrouchAction; UInputAction* CrouchAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
UInputAction* InteractAction;
public: public:
AEndlessVendettaCharacter(); AEndlessVendettaCharacter();
@ -146,6 +149,9 @@ protected:
void EquipPrimary(); void EquipPrimary();
void EquipSecondary(); void EquipSecondary();
UPROPERTY(EditDefaultsOnly, Category = "Interaction")
float InteractionRange = 250;
void Interact();
protected: protected:
// APawn interface // APawn interface