Updated Interaction,TempCharacter to cleanup

I cleaned up and removed unused functions in both interaction and tempcharacter scripts.
This commit is contained in:
MH261677 2022-11-13 22:21:51 +00:00
parent 846b21e4e9
commit d29bb501c7
5 changed files with 92 additions and 9 deletions

BIN
Content/Blueprints/BP_Interaction.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -12,7 +12,6 @@ AInteraction::AInteraction()
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
WidgetBase = CreateDefaultSubobject<UWidgetComponent>(TEXT("Widget Base Class"));
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -31,7 +30,7 @@ void AInteraction::Tick(float DeltaTime)
void AInteraction::OnInteract() void AInteraction::OnInteract()
{ {
auto spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget); UUserWidget* spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
spawnedWidget->AddToViewport(0); spawnedWidget->AddToViewport(0);
} }

View File

@ -22,12 +22,10 @@ protected:
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
UPROPERTY(VisibleAnywhere)
class UWidgetComponent* WidgetBase;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
TSubclassOf<UUserWidget> Widget; TSubclassOf<UUserWidget> Widget;
virtual void OnInteract(); virtual void OnInteract();
}; };

View File

@ -79,7 +79,6 @@ void ATempCharacter::LineTraceLogic()
} }
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor())) if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{ {
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
MyInteractable->OnInteract(); MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());

View File

@ -0,0 +1,87 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "TempCharacter.h"
#include "UObject/SoftObjectPath.h"
#include "Dialogs/Dialogs.h"
#include "Engine/GameViewportClient.h"
#include "Blueprint/UserWidget.h"
#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h"
#include "the_twilight_abyss/MerchantInteraction/Interaction.h"
// CONSTRUCTOR
ATempCharacter::ATempCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ATempCharacter::BeginPlay()
{
Super::BeginPlay();
}
//Binds the input we made in the setup player component to the forward vector
void ATempCharacter::ForwardInput(float Axis)
{
AddMovementInput(GetActorForwardVector() * Axis);
}
//Binds the input we made in the setup player component to the right vector
void ATempCharacter::RightMoveInput(float Axis)
{
AddMovementInput(GetActorRightVector() * Axis);
}
// Called every frame
void ATempCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("Move Forward / Backward"), this, &ATempCharacter::ForwardInput);
PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput);
PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput);
PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
// custom keybind Interact
}
void ATempCharacter::KeyPressed()
{
LineTraceLogic();
}
void ATempCharacter::LineTraceLogic()
{
float GlobalTrace = TraceDistance;
FHitResult OutHit;
FVector Start = GetActorLocation();
FVector End = Start + GlobalTrace * GetActorForwardVector();
FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(this);
bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
if (bHit)
{
if(OutHit.GetActor() == nullptr)
{
return;
}
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
MyInteractable->OnInteract();
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
}
}
}