Implement flanking mechanics and slightly increase enemy speed

This commit is contained in:
2025-04-16 07:28:07 +05:30
parent 10ab51e938
commit 67ac9d1935
8 changed files with 348 additions and 61 deletions

View File

@@ -11,7 +11,8 @@ enum class EEnemyBehaviorState : uint8
Chase, // Actively pursue the player
Attack, // Stop and shoot at the player
Retreat, // Move away from player when too close
Strafe // Move sideways while attacking
Strafe, // Move sideways while attacking
Flank // Execute flanking maneuver
};
UCLASS()
@@ -32,17 +33,45 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
USceneComponent* ProjectileSpawnPoint;
// Add interpolation speed for smooth movement
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MovementSpeed = 500.0f;
float InterpSpeed = 3.0f;
// Add max acceleration to prevent sudden movements
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MaxAcceleration = 2000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float AttackRange = 1500.0f;
float MovementSpeed = 1200.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MinDistanceToPlayer = 500.0f;
float FlankingSpeed = 1200.0f; // Even faster during flanking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float StrafeSpeed = 300.0f;
float FlankAngle = 60.0f; // Angle for flanking maneuver
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float FlankDistance = 2000.0f; // Distance to maintain during flanking
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float FlankPositionUpdateInterval = 1.0f; // How often to update flank position
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float AttackRange = 4000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MinDistanceToPlayer = 1500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float StrafeSpeed = 500.0f;
// Add new property for minimum distance to other enemies
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MinDistanceToOtherEnemies = 800.0f;
// Add new property for optimal combat distance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float OptimalCombatDistance = 2500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float MaxHealth = 100.0f;
@@ -74,6 +103,12 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float StateChangeChance = 0.3f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float AggressionFactor = 0.7f; // Higher values make the enemy more likely to choose aggressive actions
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float FlankingFrequency = 0.6f; // Increased chance of flanking (was 0.4f)
public:
virtual void Tick(float DeltaTime) override;
@@ -105,9 +140,28 @@ private:
void ChangeBehaviorState();
void Die();
void SmoothMove(const FVector& TargetLocation, float DeltaTime);
// AI behavior implementation functions
void PerformChase(float DeltaTime);
void PerformAttack(float DeltaTime);
void PerformRetreat(float DeltaTime);
void PerformStrafe(float DeltaTime);
void PerformFlank(float DeltaTime);
FVector CalculatePositionAwayFromOtherEnemies();
FVector CalculateFlankPosition();
FVector CurrentVelocity;
FVector TargetVelocity;
FVector LastPosition;
FVector FlankPosition;
float FlankTimer;
bool bIsFlankingRight;
FTimerHandle FlankUpdateTimer;
float LastFlankUpdateTime;
FVector CurrentFlankTarget;
bool bInitializedFlank;
};