Added InteractNPC to Line Trace for Interact

This commit is contained in:
Philip W 2023-02-02 03:15:50 +00:00
parent 5c5b915225
commit acefce8bbc
6 changed files with 89 additions and 8 deletions

Binary file not shown.

BIN
Content/Dialogue/DialogueTest.umap (Stored with Git LFS)

Binary file not shown.

BIN
Content/Dialogue/NPCTest.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -29,8 +29,6 @@ void UDialogueNPC::BeginPlay()
DialogueText = Cast<UTextBlock>(DialogueWidgetInstance->GetWidgetFromName("Text_Dialogue"));
NextButton = Cast<UButton>(DialogueWidgetInstance->GetWidgetFromName("Button_Next"));
NextButton->OnClicked.AddDynamic(this, &UDialogueNPC::NextDialogue);
StartDialogue();
}

View File

@ -0,0 +1,54 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "InteractNPC.h"
#include "DialogueNPC.h"
// Sets default values for this component's properties
UInteractNPC::UInteractNPC()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UInteractNPC::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UInteractNPC::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UInteractNPC::Interact()
{
FVector Start = GetOwner()->GetActorLocation();
FVector End = GetOwner()->GetActorForwardVector() * 100.0f + Start;
FCollisionQueryParams CollisionParams;
CollisionParams.AddIgnoredActor(GetOwner());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams))
{
//UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *HitResult.GetActor()->GetName());
if (HitResult.GetActor()->Tags.Contains("NPC"))
{
//DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5.0f, 0, 10.0f);
HitResult.GetActor()->FindComponentByClass<UDialogueNPC>()->StartDialogue();
}
//DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 5.0f, 0, 10.0f);
}
}

View File

@ -0,0 +1,29 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "InteractNPC.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class THE_TWILIGHT_ABYSS_API UInteractNPC : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UInteractNPC();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION(BlueprintCallable)
void Interact();
};