Compare commits

..

3 Commits

Author SHA1 Message Date
baz 5e0433905f Rotate Healthbar to face Player Camera in Tick 2024-03-09 03:52:14 +00:00
baz a43ec2c068 Add getter for player CameraComponent 2024-03-09 03:51:34 +00:00
baz fdfa37a346 UpdateHealthbar on BindOwner 2024-03-09 03:51:16 +00:00
5 changed files with 31 additions and 1 deletions

View File

@ -8,6 +8,8 @@
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/BlackboardData.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
#include "UI/EnemyHealthbarUserWidget.h"
#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()
{
Super::PlayOnFireAnimations();

View File

@ -53,6 +53,9 @@ public:
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
private:
virtual void PlayOnFireAnimations() override;

View File

@ -826,3 +826,8 @@ void APlayerCharacter::SetIsThrowing(bool bIsThrowing)
{
IsThrowing = bIsThrowing;
}
UCameraComponent* APlayerCharacter::GetCameraComponent()
{
return CameraComponent;
}

View File

@ -242,6 +242,8 @@ public:
UFUNCTION(BlueprintCallable)
void SetIsThrowing(bool bIsThrowing);
UCameraComponent* GetCameraComponent();
protected:
virtual void CalculateHits(TArray<FHitResult>* hits, FVector* dir) override;

View File

@ -12,7 +12,8 @@ void UEnemyHealthbarUserWidget::BindOwner(AEnemyCharacter* NewOwner)
if (Owner)
{
auto healthComponent = Owner->GetHealthComponent();
healthComponent->OnDamaged.BindUFunction(this, "UpdateHealthbar");
healthComponent->OnDamaged.BindUFunction(this, "UpdateHealthbar");
UpdateHealthbar();
}
}