mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Enemy AI
This commit is contained in:
parent
242222a4d7
commit
f2bdec7ad7
14 changed files with 200 additions and 21 deletions
|
|
@ -27,9 +27,11 @@ public partial class Alert : EnemyStateBase
|
|||
base.EnterState();
|
||||
GD.Print($"Entered {Name}");
|
||||
NavigationModule.Init(MainObject);
|
||||
|
||||
PlayerDetection.SetRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
|
||||
_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
//_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.ViewRange);
|
||||
//GD.Print($"Player In Range: {_isPlayerInRange}");
|
||||
|
||||
PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange;
|
||||
|
||||
|
|
@ -38,10 +40,8 @@ public partial class Alert : EnemyStateBase
|
|||
DamageReceiver.ChangeState(true);
|
||||
|
||||
DamageReceiver.HealthProvider.ResourceDepleted += HealthProviderOnResourceDepleted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void HealthProviderOnResourceDepleted()
|
||||
{
|
||||
ChangeState(EnemyState.Dead);
|
||||
|
|
@ -68,14 +68,14 @@ public partial class Alert : EnemyStateBase
|
|||
|
||||
private void PlayerDetectionOnPlayerInRange()
|
||||
{
|
||||
_isPlayerInRange = true;
|
||||
//_isPlayerInRange = true;
|
||||
GD.Print("Player In Range");
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
base.PhysicsProcessState(delta);
|
||||
if (_isPlayerInRange && PlayerDetection.IsPlayerInSight())
|
||||
if (PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.ViewRange) && PlayerDetection.IsPlayerInSight())
|
||||
{
|
||||
GD.Print("Player is in sight, shooting");
|
||||
StateMachine.SetState(EnemyState.Shooting);
|
||||
|
|
|
|||
8
Scripts/Components/FSM/Enemy/Dead.cs
Normal file
8
Scripts/Components/FSM/Enemy/Dead.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Cirno.Scripts.Enums;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Enemy;
|
||||
|
||||
public partial class Dead : EnemyStateBase
|
||||
{
|
||||
public override EnemyState StateId => EnemyState.Dead;
|
||||
}
|
||||
1
Scripts/Components/FSM/Enemy/Dead.cs.uid
Normal file
1
Scripts/Components/FSM/Enemy/Dead.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://4hwtlc1ftjsc
|
||||
|
|
@ -32,7 +32,7 @@ public partial class Idle : EnemyStateBase
|
|||
GD.Print("Entered Idle");
|
||||
PlayerDetection.SetRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
|
||||
_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.ViewRange);
|
||||
|
||||
PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public partial class PlayerDetectionModule : Area2D
|
|||
return false;
|
||||
}
|
||||
|
||||
return this.GlobalPosition.DistanceTo(GameManager.Instance.PlayerPosition.Value) < range;
|
||||
return this.GlobalPosition.DistanceTo(GameManager.Instance.PlayerPosition.Value) <= range;
|
||||
}
|
||||
|
||||
public bool IsPlayerInSight()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public partial class Shooting : EnemyStateBase
|
|||
base.EnterState();
|
||||
GD.Print($"Entered {Name}");
|
||||
|
||||
_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
//_isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.ViewRange);
|
||||
|
||||
PlayerDetection.PlayerOutOfRange += PlayerDetectionOnPlayerOutOfRange;
|
||||
|
||||
|
|
@ -55,7 +55,6 @@ public partial class Shooting : EnemyStateBase
|
|||
|
||||
private void PlayerDetectionOnPlayerOutOfRange()
|
||||
{
|
||||
_isPlayerInRange = false;
|
||||
StateMachine.SetState(EnemyState.Alert);
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ public partial class Shooting : EnemyStateBase
|
|||
{
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
if (_isPlayerInRange && PlayerDetection.IsPlayerInSight())
|
||||
if (PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.ViewRange) && PlayerDetection.IsPlayerInSight())
|
||||
{
|
||||
// SHOOT
|
||||
Shoot();
|
||||
|
|
@ -84,7 +83,6 @@ public partial class Shooting : EnemyStateBase
|
|||
{
|
||||
StateMachine.SetState(EnemyState.Alert);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
|
|
@ -92,7 +90,6 @@ public partial class Shooting : EnemyStateBase
|
|||
if (EquippedWeapon == null) return;
|
||||
if (!PlayerDetection.LastKnownPlayerPosition.HasValue) return;
|
||||
|
||||
|
||||
var direction = ( PlayerDetection.LastKnownPlayerPosition.Value - MainObject.GlobalPosition).Normalized();
|
||||
|
||||
// Shoot at the player's last known position
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public partial class EnemyResource : Resource
|
|||
[Export] public Array<LootDrop> LootDrops { get; private set; }
|
||||
|
||||
[ExportCategory("AI")] [Export] public float PlayerDetectionRange { get; private set; } = 90f;
|
||||
[Export] public float ViewRange { get; private set; } = 120f;
|
||||
[Export] public float AlarmReactRange { get; private set; }
|
||||
[Export] public float PlayerDisengageRange { get; private set; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue