mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 01:35:53 +00:00
Added reaction time to enemies
This commit is contained in:
parent
1c4897f054
commit
543f5f0d6b
11 changed files with 63 additions and 31 deletions
|
|
@ -97,7 +97,7 @@ public partial class Alert : EnemyStateBase
|
|||
MoveTowardsPosition(PlayerDetection.LastKnownPlayerPosition.Value);
|
||||
}
|
||||
|
||||
NavigationModule.Move();
|
||||
NavigationModule.Move(StorageModule.EnemyData.MovementSpeed);
|
||||
|
||||
StorageModule.FacingDirection = MainObject.Velocity.SnapToCardinal().Normalized();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Resources.Loot;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
|
@ -10,6 +11,8 @@ public partial class EnemyStorageModule : Node2D
|
|||
{
|
||||
[Export]
|
||||
public EnemyFSMProxy Root { get; private set; }
|
||||
|
||||
public EnemyResource EnemyData => Root.EnemyResource;
|
||||
|
||||
public Vector2 MovementDirection { get; set; }
|
||||
public Vector2 FacingDirection { get; set; }
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public partial class NavigationMovementModule : Node2D
|
|||
_lastTargetPosition = target;
|
||||
}
|
||||
|
||||
public void Move()
|
||||
public void Move(float movementSpeed)
|
||||
{
|
||||
if (!_lastTargetPosition.HasValue)
|
||||
{
|
||||
|
|
@ -43,7 +43,7 @@ public partial class NavigationMovementModule : Node2D
|
|||
|
||||
var nextPathPosition = _navigationAgent.GetNextPathPosition();
|
||||
|
||||
var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * StorageModule.MovementSpeed;
|
||||
var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * movementSpeed;
|
||||
|
||||
if (_navigationAgent.AvoidanceEnabled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,14 +20,18 @@ public partial class Shooting : EnemyStateBase
|
|||
[Export]
|
||||
public NavigationMovementModule NavigationModule { get; private set; }
|
||||
|
||||
[Export] public float MaxStrafeDistance { get; private set; } = 64f;
|
||||
[Export] public float MinStrafeDistance { get; private set; } = 16f;
|
||||
// [Export] public float MaxStrafeDistance { get; private set; } = 64f;
|
||||
// [Export] public float MinStrafeDistance { get; private set; } = 16f;
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
private bool _isPlayerInRange = false;
|
||||
|
||||
private Vector2? _currentStrafeTarget = null;
|
||||
|
||||
private float _strafeSpeed => StorageModule.EnemyData.StrafeSpeed;
|
||||
|
||||
private double _responseTimer = 0;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
|
@ -45,18 +49,8 @@ public partial class Shooting : EnemyStateBase
|
|||
EquippedWeapon.WeaponData = StorageModule.Root.EnemyResource.Weapon;
|
||||
|
||||
_currentStrafeTarget = null;
|
||||
// PlayerDetection.SetRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
//
|
||||
// _isPlayerInRange = PlayerDetection.IsPlayerInRange(StorageModule.Root.EnemyResource.PlayerDetectionRange);
|
||||
//
|
||||
// PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange;
|
||||
//
|
||||
// PlayerDetection.PlayerOutOfRange += PlayerDetectionOnPlayerOutOfRange;
|
||||
//
|
||||
// DamageReceiver.ChangeState(true);
|
||||
//
|
||||
// DamageReceiver.HealthProvider.ResourceDepleted += HealthProviderOnResourceDepleted;
|
||||
|
||||
|
||||
_responseTimer = 0;
|
||||
}
|
||||
|
||||
private void HealthProviderOnResourceDepleted()
|
||||
|
|
@ -93,10 +87,21 @@ public partial class Shooting : EnemyStateBase
|
|||
// SHOOT
|
||||
Shoot();
|
||||
|
||||
// Check if a strafe position is needed
|
||||
if (!_currentStrafeTarget.HasValue || NavigationModule.IsNavigationFinished())
|
||||
if (_strafeSpeed > 0)
|
||||
{
|
||||
_currentStrafeTarget = CalculateStrafePosition();
|
||||
// Check if a strafe position is needed
|
||||
if (!_currentStrafeTarget.HasValue || NavigationModule.IsNavigationFinished())
|
||||
{
|
||||
if (_responseTimer < StorageModule.EnemyData.ResponseTime)
|
||||
{
|
||||
_responseTimer += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentStrafeTarget = CalculateStrafePosition();
|
||||
_responseTimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -108,7 +113,7 @@ public partial class Shooting : EnemyStateBase
|
|||
if (_currentStrafeTarget.HasValue)
|
||||
{
|
||||
NavigationModule.SetTarget(_currentStrafeTarget.Value);
|
||||
NavigationModule.Move();
|
||||
NavigationModule.Move(_strafeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +134,7 @@ public partial class Shooting : EnemyStateBase
|
|||
|
||||
for (float factor = 1f; factor > 0.25f; factor *= 0.75f)
|
||||
{
|
||||
float strafeDistance = Mathf.Lerp(MinStrafeDistance, MaxStrafeDistance, factor);
|
||||
float strafeDistance = Mathf.Lerp(StorageModule.EnemyData.MinStrafeDistance, StorageModule.EnemyData.MaxStrafeDistance, factor);
|
||||
Vector2 newPos = enemyPos + (tryLeftFirst ? leftStrafe : rightStrafe) * strafeDistance;
|
||||
if (NavigationModule.IsNavigable(newPos) && PlayerDetection.HasLineOfSight(newPos, playerPos))
|
||||
{
|
||||
|
|
@ -139,7 +144,7 @@ public partial class Shooting : EnemyStateBase
|
|||
|
||||
for (float factor = 1f; factor > 0.25f; factor *= 0.75f)
|
||||
{
|
||||
float strafeDistance = Mathf.Lerp(MinStrafeDistance, MaxStrafeDistance, factor);
|
||||
float strafeDistance = Mathf.Lerp(StorageModule.EnemyData.MinStrafeDistance, StorageModule.EnemyData.MaxStrafeDistance, factor);
|
||||
Vector2 newPos = enemyPos + (tryLeftFirst ? rightStrafe : leftStrafe) * strafeDistance;
|
||||
if (NavigationModule.IsNavigable(newPos) && PlayerDetection.HasLineOfSight(newPos, playerPos))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue