Updated Combat so that the Camera Stays Locked on During Combat

This commit is contained in:
Philip W 2023-05-12 14:38:58 +01:00
parent dd72b47a6d
commit 73204efa31
4 changed files with 45 additions and 35 deletions

BIN
Content/BlueprintAI/AI/AIBruh.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

View File

@ -18,6 +18,7 @@
// Sets default values
ATurnBaseCombatV2::ATurnBaseCombatV2()
{
PrimaryActorTick.bCanEverTick = true;
if (HUDWidget == nullptr)
{
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI"));
@ -57,37 +58,12 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy, const bool bWasShot)
PlayerController->SetInputMode(FInputModeGameAndUI());
PlayerController->bShowMouseCursor = true;
FProperty* IsBossProperty = FindFieldChecked<FProperty>(EnemyActor->GetClass(), "IsBoss");
const FBoolProperty* IsBossBoolProperty = CastFieldChecked<FBoolProperty>(IsBossProperty);
if (IsBossBoolProperty->GetPropertyValue_InContainer(EnemyActor))
{
FOutputDeviceNull AR;
const FString Command = FString::Printf(TEXT("TriggerCombatAnimation true"));
EnemyActor->CallFunctionByNameWithArguments(*Command, AR, nullptr, true);
FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation();
Direction.Normalize();
FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator();
const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), EnemyActor->GetActorLocation());
LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
PlayerController->SetControlRotation(LookAtRotation);
}
else
{
FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation();
Direction.Normalize();
FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator();
const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), Cast<USkeletalMeshComponent>(EnemyActor->FindComponentByClass<USkeletalMeshComponent>())->GetComponentLocation());
LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
PlayerController->SetControlRotation(LookAtRotation);
}
FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation();
Direction.Normalize();
FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator();
const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), EnemyActor->GetActorLocation());
LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
PlayerController->SetControlRotation(LookAtRotation);
// FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation();
// Direction.Normalize();
// FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator();
// const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), EnemyActor->GetActorLocation());
// LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
// PlayerController->SetControlRotation(LookAtRotation);
if (EnemyBlackboard->GetValueAsBool("IsInCombat")) return;
EnemyBlackboard->SetValueAsBool("IsInCombat", true);
@ -266,6 +242,39 @@ void ATurnBaseCombatV2::BeginPlay()
HealButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::HealButtonOnClick);
}
void ATurnBaseCombatV2::Tick(const float DeltaTime)
{
Super::Tick(DeltaTime);
if (bIsInCombat)
{
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
FProperty* IsBossProperty = FindFieldChecked<FProperty>(EnemyActor->GetClass(), "IsBoss");
const FBoolProperty* IsBossBoolProperty = CastFieldChecked<FBoolProperty>(IsBossProperty);
if (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<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), EnemyActor->GetActorLocation());
LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
PlayerController->SetControlRotation(LookAtRotation);
}
else
{
FVector Direction = EnemyActor->GetActorLocation() - PlayerActor->GetActorLocation();
Direction.Normalize();
FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator();
const FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->GetComponentLocation(), Cast<USkeletalMeshComponent>(EnemyActor->FindComponentByClass<USkeletalMeshComponent>())->GetComponentLocation());
LookAtRotation.Pitch = NewRotation.Pitch - PlayerActor->GetActorRotation().Pitch;
Cast<UCameraComponent>(PlayerActor->FindComponentByClass<UCameraComponent>())->SetWorldRotation(LookAtRotation);
}
}
}
void ATurnBaseCombatV2::ExecuteCast(FString Combo)
{
if (!IsValidCombo(Combo))

View File

@ -121,6 +121,7 @@ public:
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
void ExecuteCast(FString Combo);
void UseActionPoint();
void ReuseActionPoint();