Rotate Healthbar to face Player Camera in Tick
This commit is contained in:
parent
a43ec2c068
commit
5e0433905f
|
@ -8,6 +8,8 @@
|
||||||
#include "BehaviorTree/BehaviorTree.h"
|
#include "BehaviorTree/BehaviorTree.h"
|
||||||
#include "BehaviorTree/BlackboardComponent.h"
|
#include "BehaviorTree/BlackboardComponent.h"
|
||||||
#include "BehaviorTree/BlackboardData.h"
|
#include "BehaviorTree/BlackboardData.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "UI/EnemyHealthbarUserWidget.h"
|
#include "UI/EnemyHealthbarUserWidget.h"
|
||||||
|
|
||||||
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
#define COLLISION_WEAPON ECC_GameTraceChannel1
|
||||||
|
@ -78,6 +80,23 @@ void AEnemyCharacter::BeginPlay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AEnemyCharacter::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
if (PlayerCharacter && HealthbarWidgetComponent->GetWidget())
|
||||||
|
{
|
||||||
|
FVector ActorLocation = GetActorLocation();
|
||||||
|
|
||||||
|
UCameraComponent* PlayerCamera = PlayerCharacter->GetCameraComponent();
|
||||||
|
FVector PlayerLocation = PlayerCamera->GetComponentTransform().GetLocation();
|
||||||
|
|
||||||
|
FRotator rotation = UKismetMathLibrary::FindLookAtRotation(ActorLocation, PlayerLocation);
|
||||||
|
HealthbarWidgetComponent->SetWorldRotation(rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AEnemyCharacter::PlayOnFireAnimations()
|
void AEnemyCharacter::PlayOnFireAnimations()
|
||||||
{
|
{
|
||||||
Super::PlayOnFireAnimations();
|
Super::PlayOnFireAnimations();
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void PlayOnFireAnimations() override;
|
virtual void PlayOnFireAnimations() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue