feat: add interaction input, implement in controller

Added interaction input.
Modified InteractionComponent - write ptr to hit object.
Implemented interact action in player controller.
This commit is contained in:
Kubson96 2025-02-17 15:28:18 +01:00
parent adddc1352c
commit b97d63bad5
9 changed files with 36 additions and 5 deletions

View File

@ -20,6 +20,14 @@
"TargetAllowList": [
"Editor"
]
},
{
"Name": "Omniverse",
"Enabled": false
},
{
"Name": "MDL",
"Enabled": false
}
]
}

View File

@ -24,6 +24,8 @@ void AExoPlayerController::BeginPlay()
}
PlayerCharacter = GetPawn<ACharacter>();
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
}
void AExoPlayerController::PlayerTick(float DeltaTime)
@ -39,6 +41,7 @@ void AExoPlayerController::SetupInputComponent()
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Move);
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Look);
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
}
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
@ -64,3 +67,10 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
AddYawInput(InputAxisVector.X);
AddPitchInput(InputAxisVector.Y);
}
void AExoPlayerController::Interact(const FInputActionValue& InputActionValue)
{
if (InteractionComponent->InteractedActor)
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
}

View File

@ -26,12 +26,13 @@ void UInteractionComponent::CheckForInteractable()
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
if (bHit && HitResult.GetActor())
if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements<UInteractable>())
{
if (HitResult.GetActor()->Implements<UInteractable>())
{
IInteractable::Execute_Interact(HitResult.GetActor());
}
InteractedActor = HitResult.GetActor();
}
else
{
InteractedActor = nullptr;
}
if (bShowDebugLine)

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include <Player/InteractionComponent.h>
#include "ExoPlayerController.generated.h"
class UInputMappingContext;
@ -31,6 +32,9 @@ protected:
UFUNCTION(BlueprintCallable, Category = "Input")
void Look(const FInputActionValue& InputActionValue);
UFUNCTION(BlueprintCallable, Category = "Input")
void Interact(const FInputActionValue& InputActionValue);
protected:
UPROPERTY(EditAnywhere, Category = "Input")
TObjectPtr<UInputMappingContext> InputContext;
@ -41,6 +45,12 @@ protected:
UPROPERTY(EditAnywhere, Category = "Input")
TObjectPtr<UInputAction> LookAction;
UPROPERTY(EditAnywhere, Category = "Input")
TObjectPtr<UInputAction> InteractAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
TObjectPtr<ACharacter> PlayerCharacter;
private:
UInteractionComponent* InteractionComponent;
};

View File

@ -21,6 +21,8 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debug")
bool bShowDebugLine = false;
AActor *InteractedActor = nullptr;
protected:
// Called when the game starts
virtual void BeginPlay() override;