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:
parent
adddc1352c
commit
b97d63bad5
Binary file not shown.
Binary file not shown.
BIN
Content/Blueprints/Player/Inputs/Inputs/AI_Interact.uasset
Normal file
BIN
Content/Blueprints/Player/Inputs/Inputs/AI_Interact.uasset
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -20,6 +20,14 @@
|
||||||
"TargetAllowList": [
|
"TargetAllowList": [
|
||||||
"Editor"
|
"Editor"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Omniverse",
|
||||||
|
"Enabled": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "MDL",
|
||||||
|
"Enabled": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -24,6 +24,8 @@ void AExoPlayerController::BeginPlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerCharacter = GetPawn<ACharacter>();
|
PlayerCharacter = GetPawn<ACharacter>();
|
||||||
|
|
||||||
|
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerTick(float DeltaTime)
|
void AExoPlayerController::PlayerTick(float DeltaTime)
|
||||||
|
|
@ -39,6 +41,7 @@ void AExoPlayerController::SetupInputComponent()
|
||||||
|
|
||||||
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Move);
|
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Move);
|
||||||
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Look);
|
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Look);
|
||||||
|
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
|
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
|
||||||
|
|
@ -64,3 +67,10 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
|
||||||
AddYawInput(InputAxisVector.X);
|
AddYawInput(InputAxisVector.X);
|
||||||
AddPitchInput(InputAxisVector.Y);
|
AddPitchInput(InputAxisVector.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AExoPlayerController::Interact(const FInputActionValue& InputActionValue)
|
||||||
|
{
|
||||||
|
if (InteractionComponent->InteractedActor)
|
||||||
|
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,13 @@ void UInteractionComponent::CheckForInteractable()
|
||||||
|
|
||||||
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
|
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>())
|
InteractedActor = HitResult.GetActor();
|
||||||
{
|
}
|
||||||
IInteractable::Execute_Interact(HitResult.GetActor());
|
else
|
||||||
}
|
{
|
||||||
|
InteractedActor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bShowDebugLine)
|
if (bShowDebugLine)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
|
#include <Player/InteractionComponent.h>
|
||||||
#include "ExoPlayerController.generated.h"
|
#include "ExoPlayerController.generated.h"
|
||||||
|
|
||||||
class UInputMappingContext;
|
class UInputMappingContext;
|
||||||
|
|
@ -31,6 +32,9 @@ protected:
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void Look(const FInputActionValue& InputActionValue);
|
void Look(const FInputActionValue& InputActionValue);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
|
void Interact(const FInputActionValue& InputActionValue);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY(EditAnywhere, Category = "Input")
|
UPROPERTY(EditAnywhere, Category = "Input")
|
||||||
TObjectPtr<UInputMappingContext> InputContext;
|
TObjectPtr<UInputMappingContext> InputContext;
|
||||||
|
|
@ -41,6 +45,12 @@ protected:
|
||||||
UPROPERTY(EditAnywhere, Category = "Input")
|
UPROPERTY(EditAnywhere, Category = "Input")
|
||||||
TObjectPtr<UInputAction> LookAction;
|
TObjectPtr<UInputAction> LookAction;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Input")
|
||||||
|
TObjectPtr<UInputAction> InteractAction;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
|
||||||
TObjectPtr<ACharacter> PlayerCharacter;
|
TObjectPtr<ACharacter> PlayerCharacter;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UInteractionComponent* InteractionComponent;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debug")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debug")
|
||||||
bool bShowDebugLine = false;
|
bool bShowDebugLine = false;
|
||||||
|
|
||||||
|
AActor *InteractedActor = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts
|
// Called when the game starts
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user