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
This commit is contained in:
MH261677 2023-01-16 20:44:23 +00:00
parent 77328aa887
commit 3752a24eab
2 changed files with 55 additions and 9 deletions

View File

@ -64,11 +64,12 @@ void ATempCharacter::KeyPressed()
// Line trace logic // Line trace logic
void ATempCharacter::LineTraceLogic() void ATempCharacter::LineTraceLogic()
{ {
UE_LOG(LogTemp, Display, TEXT("LineTraceLogic firing"));
float GlobalTrace = TraceDistance; float GlobalTrace = TraceDistance;
FHitResult OutHit; FHitResult OutHit;
FVector Start = GetActorLocation(); ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
FVector End = Start + GlobalTrace * GetActorForwardVector(); FVector Start = ThisCamera->GetComponentLocation();
FVector End = Start + GlobalTrace * ThisCamera->GetForwardVector();
FCollisionQueryParams TraceParams; FCollisionQueryParams TraceParams;
TraceParams.AddIgnoredActor(this); TraceParams.AddIgnoredActor(this);
@ -106,14 +107,11 @@ void ATempCharacter::LineTraceLogic()
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
// While loop to check bisDisabled var until it changes to true // 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 InputDisabler();
FTimerHandle TimerHandle;
FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &ATempCharacter::InputDisabler);
GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 6.0f, false);
break; break;
} }
} }
@ -129,6 +127,19 @@ void ATempCharacter::InputDisabler()
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true; GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
GetWorld()->GetFirstPlayerController()->bEnableClickEvents = true; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = true;
GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = true; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = true;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
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() void ATempCharacter::InputEnabler()
@ -139,6 +150,20 @@ void ATempCharacter::InputEnabler()
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false; GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false;
GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false; GetWorld()->GetFirstPlayerController()->bEnableClickEvents = false;
GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false; GetWorld()->GetFirstPlayerController()->bEnableMouseOverEvents = false;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
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) void ATempCharacter::UseItem(class UBaseItem* Item)
@ -150,5 +175,12 @@ void ATempCharacter::UseItem(class UBaseItem* Item)
} }
} }
void ATempCharacter::BuyItem()
{
TraceDistance = 1000;
LineTraceLogic();
}

View File

@ -5,6 +5,9 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
#include "the_twilight_abyss/BaseItems/Items/BaseItem.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" #include "TempCharacter.generated.h"
UCLASS() UCLASS()
@ -56,5 +59,16 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void InputEnabler(); void InputEnabler();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
UCameraComponent* ThisCamera;
FVector OriginalCameraLocation;
FRotator OriginalCameraRotation;
int OriginalCameraFOV;
UFUNCTION(BlueprintCallable, Category= "Items")
void BuyItem();
}; };