cirnogodot/Scripts/Components/Actors/ActorFreeMovement.cs

60 lines
1.5 KiB
C#
Raw Normal View History

2025-02-18 17:40:33 +01:00
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Components.Actors;
2025-02-17 21:53:05 +01:00
using Godot;
public partial class ActorFreeMovement : MovementHandler
{
2025-02-18 17:40:33 +01:00
public override Vector2 FacingDirection
{
get => _parent.FacingDirection;
set => _parent.FacingDirection = value;
}
2025-02-17 21:53:05 +01:00
2025-02-18 17:40:33 +01:00
public override Vector2 MovementDirection
{
get => _parent.MovementDirection;
set => _parent.MovementDirection = value;
}
2025-02-23 18:08:57 +01:00
2025-03-03 15:01:12 +01:00
[Export] public StringName StrafeAction { get; private set; } = "strafe";
2025-02-23 18:08:57 +01:00
public bool IsDestroyed => _parent.IsDestroyed;
2025-02-17 21:53:05 +01:00
public override void Init(Actor parent)
{
2025-02-18 17:40:33 +01:00
base.Init(parent);
2025-02-17 21:53:05 +01:00
MovementDirection = Vector2.Zero;
2025-02-18 17:40:33 +01:00
FacingDirection = Vector2.Down;
2025-02-17 21:53:05 +01:00
}
2025-02-20 18:26:53 +01:00
public override void Update(double delta)
{
}
public override void PhysicsUpdate(double delta)
2025-02-17 21:53:05 +01:00
{
2025-02-23 18:08:57 +01:00
if (IsDestroyed) return;
2025-02-18 18:18:13 +01:00
MovementDirection = AggregateInputProviders().Normalized();
var aimingDirection = GetAimingDirection().Normalized();
var isStrafing = GetActionPressed(StrafeAction);
2025-02-18 18:18:13 +01:00
if (!isStrafing && aimingDirection.Length() > 0.1f)
{
FacingDirection = aimingDirection;
}
else if (MovementDirection != Vector2.Zero)
{
FacingDirection = MovementDirection;
}
2025-02-18 17:40:33 +01:00
2025-02-17 21:53:05 +01:00
_parent.Velocity = MovementDirection * _parent.MovementSpeed;
_parent.MoveAndSlide();
}
}