mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 11:55:54 +00:00
Test scene for new actor
This commit is contained in:
parent
17f4e11651
commit
0e15d2acba
10 changed files with 142 additions and 21 deletions
|
|
@ -27,6 +27,8 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
|
||||
[Export(PropertyHint.Layers2DPhysics)]
|
||||
public uint CollisionMask { get; set; }
|
||||
|
||||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
public bool NavigationEnabled
|
||||
{
|
||||
|
|
@ -71,7 +73,7 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
|
||||
private void AlarmManagerOnAlarmEnabled(Vector2 location)
|
||||
{
|
||||
if (NavigationEnabled && location.DistanceTo(this.GlobalPosition) <= AlarmReactRange)
|
||||
if (NavigationEnabled && location.DistanceTo(_parent.GlobalPosition) <= AlarmReactRange)
|
||||
{
|
||||
GD.Print($"Enemy {Name} alerted");
|
||||
_actorAi.State = EnemyState.Alert;
|
||||
|
|
@ -83,8 +85,7 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
{
|
||||
if (_actorAi.Ai is not AiState.Enabled)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
switch (_actorAi.State)
|
||||
{
|
||||
case EnemyState.Idle:
|
||||
|
|
@ -115,15 +116,14 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
var nextPathPosition = _navigationAgent.GetNextPathPosition();
|
||||
|
||||
var newVelocity = currentAgentPosition.DirectionTo(nextPathPosition) * _parent.MovementSpeed;
|
||||
|
||||
|
||||
|
||||
// Navigation is over, can do other things like shooting
|
||||
if (_navigationAgent.IsNavigationFinished())
|
||||
{
|
||||
// Shoot player
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
Shoot();
|
||||
}
|
||||
|
||||
// TODO: If player totally left the max range it should stop shooting and go back to idle
|
||||
|
|
@ -146,7 +146,7 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
{
|
||||
if (IsPlayerInSight)
|
||||
{
|
||||
//Shoot();
|
||||
Shoot();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,6 +154,19 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
}
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
if (EquippedWeapon == null || !_lastPlayerPosition.HasValue) return;
|
||||
|
||||
var direction = (_lastPlayerPosition.Value - _parent.GlobalPosition).Normalized();
|
||||
|
||||
// Shoot at the player's last known position
|
||||
EquippedWeapon.ShootDirection = direction;
|
||||
FacingDirection = direction;
|
||||
|
||||
EquippedWeapon.Shoot();
|
||||
}
|
||||
|
||||
public void _on_navigation_agent_2d_velocity_computed(Vector2 safeVelocity)
|
||||
{
|
||||
_parent.Velocity = safeVelocity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue