mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 13:05:53 +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
|
|
@ -25,7 +25,6 @@ public partial class AnimationHandler : ActorModule
|
|||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
|
||||
var direction = _parent.FacingDirection; //GetSnappedDirection();
|
||||
|
||||
if (_parent.Velocity.Length() > 0)
|
||||
|
|
@ -47,7 +46,7 @@ public partial class AnimationHandler : ActorModule
|
|||
|
||||
}
|
||||
|
||||
private string DirectionToString(Vector2 direction)
|
||||
protected virtual string DirectionToString(Vector2 direction)
|
||||
{
|
||||
var angle = Mathf.RadToDeg(direction.Angle());
|
||||
angle = Mathf.PosMod(angle, 360);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
8
Scripts/Components/FSM/State.cs
Normal file
8
Scripts/Components/FSM/State.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM;
|
||||
|
||||
public partial class State : Node2D
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,4 @@ public partial class CameraTargetEvent : CameraTargetPlayerEvent
|
|||
GameManager.Instance.CameraTargetObject(parent.GetNode<Node2D>(Target), Offset);
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue