diff --git a/Content/Blueprints/BP_Interaction.uasset b/Content/Blueprints/BP_Interaction.uasset index 024952c..36accd5 100644 --- a/Content/Blueprints/BP_Interaction.uasset +++ b/Content/Blueprints/BP_Interaction.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:14deaac2c8f6b6aa67592c8a806ed6059a566d3a767fbd18a092107b29913718 -size 27683 +oid sha256:4c7a00cbf616d22eba20079c3f1640b3d1c3ef86aee1bcfa4335ca32a5390a80 +size 27630 diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index df5bad3..237d6ee 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -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. PrimaryActorTick.bCanEverTick = true; - WidgetBase = CreateDefaultSubobject(TEXT("Widget Base Class")); } // Called when the game starts or when spawned @@ -31,7 +30,7 @@ void AInteraction::Tick(float DeltaTime) void AInteraction::OnInteract() { - auto spawnedWidget = CreateWidget(GetWorld(), Widget); + UUserWidget* spawnedWidget = CreateWidget(GetWorld(), Widget); spawnedWidget->AddToViewport(0); } diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index da9fd47..2fa21b1 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -22,12 +22,10 @@ protected: public: // Called every frame virtual void Tick(float DeltaTime) override; - - UPROPERTY(VisibleAnywhere) - class UWidgetComponent* WidgetBase; - + UPROPERTY(EditAnywhere) TSubclassOf Widget; virtual void OnInteract(); }; + diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index b1f86e8..83bf10b 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -79,7 +79,6 @@ void ATempCharacter::LineTraceLogic() } if (AInteraction* MyInteractable = Cast(OutHit.GetActor())) { - DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); MyInteractable->OnInteract(); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ new file mode 100644 index 0000000..83bf10b --- /dev/null +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp~ @@ -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(OutHit.GetActor())) + { + DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); + MyInteractable->OnInteract(); + UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); + } + } +}