From 3752a24eab631d9b174c2800c286c06fda137c1b Mon Sep 17 00:00:00 2001 From: MH261677 Date: Mon, 16 Jan 2023 20:44:23 +0000 Subject: [PATCH] Updated TempCharacter Created camera function which pans the camera to the object and raises FOV, Fixed multiple bugs to do with disabling input, Created BuyItem function which raises the TraceDistance temporarily so user can purchase at longer distances --- .../PlayerTemp/TempCharacter.cpp | 50 +++++++++++++++---- .../PlayerTemp/TempCharacter.h | 14 ++++++ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 9a8920b..2bec2af 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -64,11 +64,12 @@ void ATempCharacter::KeyPressed() // Line trace logic void ATempCharacter::LineTraceLogic() { + UE_LOG(LogTemp, Display, TEXT("LineTraceLogic firing")); float GlobalTrace = TraceDistance; FHitResult OutHit; - FVector Start = GetActorLocation(); - FVector End = Start + GlobalTrace * GetActorForwardVector(); - + ThisCamera = Cast(this->FindComponentByClass()); + FVector Start = ThisCamera->GetComponentLocation(); + FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector(); FCollisionQueryParams TraceParams; TraceParams.AddIgnoredActor(this); @@ -106,14 +107,11 @@ void ATempCharacter::LineTraceLogic() UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); // While loop to check bisDisabled var until it changes to true - while (MyInteractable->bisDisabled == false) + while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false) { - if (MyInteractable->bisDisabled == true) + if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true) { - //I am creating a 5 second timer here that then executes the inputdisabler function - FTimerHandle TimerHandle; - FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &ATempCharacter::InputDisabler); - GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 6.0f, false); + InputDisabler(); break; } } @@ -129,6 +127,19 @@ void ATempCharacter::InputDisabler() GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = true; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = true; + ThisCamera = Cast(this->FindComponentByClass()); + if (ThisCamera == nullptr) + { + return; + } + else + { + OriginalCameraLocation = ThisCamera->GetComponentLocation(); + OriginalCameraRotation = ThisCamera->GetComponentRotation(); + OriginalCameraFOV = ThisCamera->FieldOfView; + //ulog the originalcameralocation value + UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString()); + } } void ATempCharacter::InputEnabler() @@ -139,6 +150,20 @@ void ATempCharacter::InputEnabler() GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false; + ThisCamera = Cast(this->FindComponentByClass()); + if (ThisCamera == nullptr) + { + return; + } + else + { + ThisCamera->SetWorldLocation(OriginalCameraLocation); + ThisCamera->SetWorldRotation(OriginalCameraRotation); + ThisCamera->FieldOfView = OriginalCameraFOV; + + //ulog the originalcameralocation value + UE_LOG(LogTemp, Display, TEXT("Original Camera Location: %s"), *OriginalCameraLocation.ToString()); + } } void ATempCharacter::UseItem(class UBaseItem* Item) @@ -150,5 +175,12 @@ void ATempCharacter::UseItem(class UBaseItem* Item) } } +void ATempCharacter::BuyItem() +{ + TraceDistance = 1000; + LineTraceLogic(); +} + + diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index cc97668..4cf0350 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -5,6 +5,9 @@ #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "the_twilight_abyss/BaseItems/Items/BaseItem.h" +#include "Camera/CameraComponent.h" +#include "Evaluation/MovieSceneCameraAnimTemplate.h" +#include "Kismet/KismetMathLibrary.h" #include "TempCharacter.generated.h" UCLASS() @@ -56,5 +59,16 @@ public: UFUNCTION(BlueprintCallable) void InputEnabler(); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera") + UCameraComponent* ThisCamera; + + FVector OriginalCameraLocation; + FRotator OriginalCameraRotation; + + int OriginalCameraFOV; + + UFUNCTION(BlueprintCallable, Category= "Items") + void BuyItem(); };