Updated Character to Convert Screen Space to World for Interaction

This commit is contained in:
Philip W 2023-04-24 18:01:51 +01:00
parent 3e34ab4c5c
commit 18ceedfa03
8 changed files with 34 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -28,6 +28,10 @@ ATempCharacter::ATempCharacter()
void ATempCharacter::BeginPlay()
{
Super::BeginPlay();
FirstPlayerController = GetWorld()->GetFirstPlayerController();
WidgetPointer = Cast<UWidgetInteractionComponent>(this->GetComponentByClass(UWidgetInteractionComponent::StaticClass()));
Health = 100;
ThisCamera = Cast<UCameraComponent>(this->FindComponentByClass<UCameraComponent>());
PlayerCapsule = GetCapsuleComponent();
@ -93,6 +97,13 @@ void ATempCharacter::Sneak()
void ATempCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (CombatSystem->bIsInCombat)
{
FVector VectorRotation;
FVector WidgetLocation;
FirstPlayerController->DeprojectMousePositionToWorld(WidgetLocation, VectorRotation);
WidgetPointer->SetWorldLocationAndRotation(WidgetLocation, VectorRotation.Rotation().Quaternion());
}
}
// Gives the character the functionality

View File

@ -7,6 +7,8 @@
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
#include "Camera/CameraComponent.h"
#include "Engine/PostProcessVolume.h"
#include "Components/WidgetInteractionComponent.h"
#include "../TurnBasedCombatV2/TurnBaseCombatV2.h"
#include "TempCharacter.generated.h"
UCLASS()
@ -29,6 +31,12 @@ protected:
void Sneak();
UCapsuleComponent* PlayerCapsule;
UPROPERTY()
APlayerController* FirstPlayerController;
UPROPERTY()
UWidgetInteractionComponent* WidgetPointer;
UPROPERTY()
ATurnBaseCombatV2* CombatSystem;
public:
// Called every frame

View File

@ -36,6 +36,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
{
if (Enemy == nullptr) return;
bIsInCombat = true;
UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(Enemy->GetInstigatorController())->GetBlackboardComponent();
if (!HasSeenTutorial)
{
@ -62,7 +63,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
}
if (HUD->IsInViewport()) return;
HUD->AddToViewport();
//HUD->AddToViewport();
EnemyActor = Enemy;
ProbertiumResource = 10;
@ -77,6 +78,7 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
}
//Set to UI Mode Only
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeUIOnly());
PlayerController->bShowMouseCursor = true;
@ -100,6 +102,7 @@ void ATurnBaseCombatV2::EndCombat()
{
bEnemyHasExtraTurn = false;
bPlayerHasExtraTurn = false;
bIsInCombat = false;
for (UStatusEffect* StatusEffect : StatusEffects)
{
StatusEffect->OnExpiry(PlayerActor);
@ -516,3 +519,4 @@ void ATurnBaseCombatV2::EnemyTurn()
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
ToggleButtons();
}

View File

@ -26,6 +26,8 @@ public:
int* EnemyHealth = nullptr;
float* PlayerHealth = nullptr;
bool bIsInCombat = false;
UPROPERTY(EditDefaultsOnly)
int DefaultActionPoints = 2;
UPROPERTY(EditDefaultsOnly)