Updated Interaction.cpp

Optimized some functions and variables by storing them in beginplay
This commit is contained in:
MARCEL HARA 2023-01-23 16:14:15 +00:00
parent b9d87ee07b
commit 3f4cdf5bfa
4 changed files with 29 additions and 18 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ebb8b1c4142831775542c0bcb3400dc138a3360ffe820dd74cd460af4b914a53
size 26504
oid sha256:5efb970894cb114a37a45fac46558718d0fa4bfed2b9900eebd2a752fc71d021
size 26607

View File

@ -22,7 +22,10 @@ AInteraction::AInteraction()
void AInteraction::BeginPlay()
{
Super::BeginPlay();
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
TargetHealingLocation = HealingItem->GetActorLocation();
TargetBuffLocation = BuffItem->GetActorLocation();
}
// Called every frame
@ -80,8 +83,6 @@ void AInteraction::RemoveWidget()
void AInteraction::CameraLeftMover()
{
UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
if (TempCharacter == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
@ -90,16 +91,15 @@ void AInteraction::CameraLeftMover()
else
{
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
if (MainCamera == nullptr)
if (MainCamera == nullptr || HealingItem == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
return;
}
else
{
FVector TargetLocation = FVector(5700,-1270,4040);
FVector CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40);
}
@ -109,8 +109,6 @@ void AInteraction::CameraLeftMover()
void AInteraction::CameraRightMover()
{
UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
if (TempCharacter == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
@ -119,16 +117,15 @@ void AInteraction::CameraRightMover()
else
{
UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
if (MainCamera == nullptr)
if (MainCamera == nullptr || BuffItem == nullptr)
{
UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
return;
}
else
{
FVector TargetLocation = FVector(5260, -840, 4070);
FVector CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
CameraLocation = MainCamera->GetComponentLocation();
FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
MainCamera->SetWorldRotation(CameraRotation);
MainCamera->SetFieldOfView(40);
}

View File

@ -24,10 +24,10 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ShopDialog;
UPROPERTY(EditAnywhere)
UPROPERTY(EditAnywhere, Category= "Widgets")
TSubclassOf<UUserWidget> ItemSelector;
virtual void OnInteract();
@ -40,7 +40,7 @@ public:
UPROPERTY()
UUserWidget* ItemSelectorWidget;
UPROPERTY(EditAnywhere)
UPROPERTY(EditAnywhere, Category= "Widgets")
float WaitTimer = 8.0f;
UPROPERTY()
@ -60,5 +60,17 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player")
ACharacter* TempCharacter;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
AActor* HealingItem;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
AActor* BuffItem;
private:
FVector TargetHealingLocation;
FVector TargetBuffLocation;
FVector CameraLocation;
};

View File

@ -43,6 +43,8 @@ public:
void InputDisabler();
void LineTraceLogic();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
float Health;