From afd166c868034f7c425c2596d14b43ef3b4ee64b Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Fri, 12 May 2023 16:48:14 +0100 Subject: [PATCH] Bugfix Camera Shake Due to Spam of Animations --- .../TurnBasedCombatV2/TurnBaseCombatV2.cpp | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index b3c682e..9dd5f7c 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -58,19 +58,27 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy, const bool bWasShot) PlayerController->SetInputMode(FInputModeGameAndUI()); PlayerController->bShowMouseCursor = true; - // FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation(); - // Direction.Normalize(); - // FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator(); - // const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast(PlayerActor->FindComponentByClass())->GetComponentLocation(), EnemyActor->GetActorLocation()); - // LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch; - // PlayerController->SetControlRotation(LookAtRotation); - if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return; EnemyBlackboard->SetValueAsBool("IsInCombat", true); const FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr(Enemy); EnemyHealth = EnemyHealthPtr; + FProperty* IsBossProperty = FindFieldChecked(EnemyActor->GetClass(), "IsBoss"); + if (const FBoolProperty* IsBossBoolProperty = CastFieldChecked(IsBossProperty); IsBossBoolProperty->GetPropertyValue_InContainer(EnemyActor)) + { + FOutputDeviceNull AR; + const FString Command = FString::Printf(TEXT("TriggerCombatAnimation true")); + EnemyActor->CallFunctionByNameWithArguments(*Command, AR, nullptr, true); + FVector Direction = EnemyActor->GetActorLocation() - PlayerActor->GetActorLocation(); + Direction.Normalize(); + FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator(); + const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast(PlayerActor->FindComponentByClass())->GetComponentLocation(), EnemyActor->GetActorLocation()); + LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch; + LookAtRotation.Pitch += 10; //Offset + PlayerController->SetControlRotation(LookAtRotation); + } + if (IsValid(CombatTutorialWidgetInstance) && CombatTutorialWidgetInstance->IsInViewport()) return; if (!HasSeenTutorial) { @@ -249,20 +257,7 @@ void ATurnBaseCombatV2::Tick(const float DeltaTime) { APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); FProperty* IsBossProperty = FindFieldChecked(EnemyActor->GetClass(), "IsBoss"); - if (const FBoolProperty* IsBossBoolProperty = CastFieldChecked(IsBossProperty); IsBossBoolProperty->GetPropertyValue_InContainer(EnemyActor)) - { - FOutputDeviceNull AR; - const FString Command = FString::Printf(TEXT("TriggerCombatAnimation true")); - EnemyActor->CallFunctionByNameWithArguments(*Command, AR, nullptr, true); - - FVector Direction = EnemyActor->GetActorLocation() - PlayerActor->GetActorLocation(); - Direction.Normalize(); - FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator(); - const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast(PlayerActor->FindComponentByClass())->GetComponentLocation(), EnemyActor->GetActorLocation()); - LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch; - PlayerController->SetControlRotation(LookAtRotation); - } - else + if (const FBoolProperty* IsBossBoolProperty = CastFieldChecked(IsBossProperty); !IsBossBoolProperty->GetPropertyValue_InContainer(EnemyActor)) { FVector Direction = EnemyActor->GetActorLocation() - PlayerActor->GetActorLocation(); Direction.Normalize();