feat: add interaction interface, component and test item
Added Interactable - interface for interaction system. Implemented in test item (TestBox). Created interaction component for character Added interaction input - not implemented.
This commit is contained in:
parent
75e145c193
commit
adddc1352c
Binary file not shown.
BIN
Content/Blueprints/Items/TestBox.uasset
Normal file
BIN
Content/Blueprints/Items/TestBox.uasset
Normal file
Binary file not shown.
Binary file not shown.
BIN
Content/Blueprints/Player/Inputs/Inputs/AI_Interaction.uasset
Normal file
BIN
Content/Blueprints/Player/Inputs/Inputs/AI_Interaction.uasset
Normal file
Binary file not shown.
Binary file not shown.
47
Source/Exo/Private/Player/InteractionComponent.cpp
Normal file
47
Source/Exo/Private/Player/InteractionComponent.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include "Player/InteractionComponent.h"
|
||||
|
||||
UInteractionComponent::UInteractionComponent()
|
||||
{
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
}
|
||||
|
||||
|
||||
void UInteractionComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
|
||||
void UInteractionComponent::CheckForInteractable()
|
||||
{
|
||||
AActor* Owner = GetOwner();
|
||||
|
||||
FVector LineStart = Owner->GetActorLocation();
|
||||
FVector ForwardVector = Owner->GetActorForwardVector();
|
||||
FVector LineEnd = LineStart + (ForwardVector * InteractionDistance);
|
||||
|
||||
FHitResult HitResult;
|
||||
FCollisionQueryParams QueryParams;
|
||||
QueryParams.AddIgnoredActor(Owner);
|
||||
|
||||
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
|
||||
|
||||
if (bHit && HitResult.GetActor())
|
||||
{
|
||||
if (HitResult.GetActor()->Implements<UInteractable>())
|
||||
{
|
||||
IInteractable::Execute_Interact(HitResult.GetActor());
|
||||
}
|
||||
}
|
||||
|
||||
if (bShowDebugLine)
|
||||
DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
void UInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
CheckForInteractable();
|
||||
}
|
||||
|
||||
20
Source/Exo/Public/Interfaces/Interactable.h
Normal file
20
Source/Exo/Public/Interfaces/Interactable.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "Interactable.generated.h"
|
||||
|
||||
UINTERFACE(MinimalAPI, Blueprintable)
|
||||
class UInteractable : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
class EXO_API IInteractable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
|
||||
void Interact();
|
||||
};
|
||||
35
Source/Exo/Public/Player/InteractionComponent.h
Normal file
35
Source/Exo/Public/Player/InteractionComponent.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Interfaces/Interactable.h"
|
||||
#include "InteractionComponent.generated.h"
|
||||
|
||||
|
||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||
class EXO_API UInteractionComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UInteractionComponent();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Settings")
|
||||
float InteractionDistance = 100.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Debug")
|
||||
bool bShowDebugLine = false;
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
private:
|
||||
void CheckForInteractable();
|
||||
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user