Add properties and methods to know when attack the player

This commit is contained in:
Emilie Schott 2025-01-24 01:04:42 +01:00
parent 4a7119aecf
commit 52b996d3f6
8 changed files with 37 additions and 10 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,7 @@
ALMEnemy::ALMEnemy()
{
PrimaryActorTick.bCanEverTick = true;
EnemyState = EEnemyState::EES_Chasing;
}
void ALMEnemy::BeginPlay()
@ -12,6 +13,11 @@ void ALMEnemy::BeginPlay()
Super::BeginPlay();
}
double ALMEnemy::GetDistanceToTarget(const AActor* TargetedActor)
{
return (TargetedActor->GetActorLocation() - GetActorLocation()).Length();
}
void ALMEnemy::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

View File

@ -5,6 +5,7 @@
ALMMeleeEnemy::ALMMeleeEnemy()
{
PrimaryActorTick.bCanEverTick = true;
AttackingRadius = 100.f;
}
void ALMMeleeEnemy::BeginPlay()
@ -22,4 +23,3 @@ void ALMMeleeEnemy::SetupPlayerInputComponent(UInputComponent* PlayerInputCompon
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}

View File

@ -6,6 +6,13 @@
#include "GameFramework/Character.h"
#include "LMEnemy.generated.h"
UENUM(BlueprintType)
enum class EEnemyState : uint8
{
EES_Chasing UMETA(DisplayName = "Chasing"),
EES_Attacking UMETA(DisplayName = "Attacking")
};
UCLASS()
class LEGUMEMIX_API ALMEnemy : public ACharacter
{
@ -18,4 +25,18 @@ public:
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix")
EEnemyState EnemyState;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = "Legumix")
double AttackingRadius;
/**
* Returns the distance between the enemy and a target.
* @param TargetedActor
* @returns the distance
*/
UFUNCTION(BlueprintCallable, Category="Legumix", meta=(ReturnDisplayName="Distance", DefaultToSelf="TargetedActor"))
double GetDistanceToTarget(const AActor* TargetedActor);
};

View File

@ -18,5 +18,5 @@ public:
protected:
virtual void BeginPlay() override;
};