From d100a85a0d11c0662c4676f79c8b8b0b84021a13 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Mon, 6 Mar 2023 04:28:13 +0000 Subject: [PATCH] Updated Combat to Set Camera to Face Enemy --- .../Tutorial_Wood_Texture.uasset | 4 ++-- Content/Levels/Build.umap | 4 ++-- Content/Levels/C2Plane.uasset | 4 ++-- .../PlayerTemp/TempCharacter.cpp | 2 +- .../PlayerTemp/TempCharacter.h | 17 ++++++++--------- .../TurnBasedCombatV2/TurnBaseCombatV2.cpp | 15 +++++++++++---- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Content/Assets/Objects/Tutrorial_Assets/Tutorial_Wood_Texture.uasset b/Content/Assets/Objects/Tutrorial_Assets/Tutorial_Wood_Texture.uasset index 25eab3b..457459a 100644 --- a/Content/Assets/Objects/Tutrorial_Assets/Tutorial_Wood_Texture.uasset +++ b/Content/Assets/Objects/Tutrorial_Assets/Tutorial_Wood_Texture.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d52c98b0fb8550caa04d2a1e0e66b2a9d81e095d6d68a940014197c0d7e187de -size 15206 +oid sha256:2647badca7908e08eeead0a12ce0e83cf6851694aab3d48e687fd503bd32b97a +size 14829 diff --git a/Content/Levels/Build.umap b/Content/Levels/Build.umap index db52709..ddc5b00 100644 --- a/Content/Levels/Build.umap +++ b/Content/Levels/Build.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba653b8f9bd4c144ad6b77c4fae077fc8b3e88deb2e982787a647399d2e554e3 -size 354425 +oid sha256:efe6873fdfa3179afbd11ac1d6f5d8b101610fa924f6b72c8e9212f730ac0c9f +size 413107 diff --git a/Content/Levels/C2Plane.uasset b/Content/Levels/C2Plane.uasset index 1ce3908..2071a8c 100644 --- a/Content/Levels/C2Plane.uasset +++ b/Content/Levels/C2Plane.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:baee4795cfc5a4580a544bf20e49098d8cd11082dc60ddd2f9b962d836435e92 -size 42608 +oid sha256:e2bd6c119bc7c4cab2cac2b19a010824930db6f78daeff4872d8819ba6513139 +size 42550 diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index 2adb426..30376e3 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -122,7 +122,7 @@ void ATempCharacter::KeyPressed() // Line trace logic void ATempCharacter::LineTraceLogic() { - UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated")); + //UE_LOG(LogTemp, Display, TEXT("LineTraceLogic activated")); float GlobalTrace = TraceDistance; FHitResult OutHit; ThisCamera = Cast(this->FindComponentByClass()); diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 961cb21..f56a83c 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -28,7 +28,6 @@ protected: UFUNCTION() void Sneak(); - UCapsuleComponent* PlayerCapsule; public: @@ -37,15 +36,15 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true")) class UInventoryComponent* Inventory; //Using the InventoryComponent class - + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets") UUserWidget* ItemSelectorWidget; - + // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; - + void KeyPressed(); - + UPROPERTY(EditAnyWhere) float TraceDistance = 300; @@ -54,7 +53,7 @@ public: UPROPERTY() class UPawnNoiseEmitterComponent* NoiseEmitter; - + UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health") float Health; @@ -63,7 +62,7 @@ public: UPROPERTY(VisibleDefaultsOnly, Category = "LineTrace") bool bHit; - + //Using the item in the inventory UFUNCTION(BlueprintCallable, Category= "Items") void UseItem(class UBaseItem* Item); // Overriding the BaseItem Class @@ -75,7 +74,7 @@ public: UCameraComponent* ThisCamera; FVector OriginalCameraLocation; - + FRotator OriginalCameraRotation; int OriginalCameraFOV; @@ -90,7 +89,7 @@ public: APostProcessVolume* PostProcessVolume; - TArray AIActors; + TArray AIActors; FName Enemy; diff --git a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 3bbffa9..8361f5c 100644 --- a/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -36,7 +36,6 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) EnemyBlackboard->SetValueAsBool("IsInCombat", true); FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr(Enemy); - EnemyHealth = EnemyHealthPtr; if (HUD->IsInViewport()) return; @@ -58,6 +57,14 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) PlayerController->SetInputMode(FInputModeUIOnly()); PlayerController->bShowMouseCursor = true; + FVector Direction = Enemy->GetActorLocation() - PlayerActor->GetActorLocation(); + Direction.Normalize(); + FRotator LookAtRotation = FRotationMatrix::MakeFromX(Direction).Rotator(); + LookAtRotation.Pitch = -9.0f; + PlayerController->SetControlRotation(LookAtRotation); + + //DrawDebugPoint(GetWorld(), Enemy->GetActorLocation(), 10, FColor::Red, false, 10); + CurrentComboString = ""; UpdateComboString(CurrentComboString); RevertActionPoints(); @@ -72,7 +79,7 @@ void ATurnBaseCombatV2::EndCombat() { StatusEffect->OnExpiry(PlayerActor); } - + HUD->RemoveFromParent(); APawn* PlayerPawn = Cast(GetWorld()->GetFirstPlayerController()->GetPawn()); PlayerPawn->bUseControllerRotationYaw = true; @@ -217,7 +224,7 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); break; } - + //Ends Combat if either the player or enemy is dead if (*EnemyHealth <= 0) { @@ -288,7 +295,7 @@ void ATurnBaseCombatV2::SwitchTurn() //bIsPlayerTurn = !bIsPlayerTurn; TurnIndicatorTextBlock->SetText(FText::FromString("Enemy Turn")); ToggleButtons(); - + FTimerHandle UnusedHandle; GetWorldTimerManager().SetTimer(UnusedHandle, this, &ATurnBaseCombatV2::EnemyTurn, 2.0f, false);