Better free movement

This commit is contained in:
Marco 2025-02-18 18:18:13 +01:00
commit 388747ccb3
7 changed files with 108 additions and 15 deletions

View file

@ -1,4 +1,5 @@
using Godot;
using System.Collections.Generic;
using Godot;
namespace Cirno.Scripts.Components.Actors;
@ -46,15 +47,39 @@ public partial class AnimationHandler : Node2D
var angle = Mathf.RadToDeg(direction.Angle());
angle = Mathf.PosMod(angle, 360);
if (angle >= 337.5 || angle < 22.5) return "right";
if (angle >= 22.5 && angle < 67.5) return "up_right";
if (angle >= 67.5 && angle < 112.5) return "up";
if (angle >= 112.5 && angle < 157.5) return "up_left";
if (angle >= 157.5 && angle < 202.5) return "left";
if (angle >= 202.5 && angle < 247.5) return "down_left";
if (angle >= 247.5 && angle < 292.5) return "down";
if (angle >= 292.5 && angle < 337.5) return "down_right";
if (angle >= 337.5 || angle < 22.5) return _directionsTable[FacingDirection.Right];
if (angle >= 22.5 && angle < 67.5) return _directionsTable[FacingDirection.DownRight];
if (angle >= 67.5 && angle < 112.5) return _directionsTable[FacingDirection.Down];
if (angle >= 112.5 && angle < 157.5) return _directionsTable[FacingDirection.DownLeft];
if (angle >= 157.5 && angle < 202.5) return _directionsTable[FacingDirection.Left];
if (angle >= 202.5 && angle < 247.5) return _directionsTable[FacingDirection.UpLeft];
if (angle >= 247.5 && angle < 292.5) return _directionsTable[FacingDirection.Up];
if (angle >= 292.5 && angle < 337.5) return _directionsTable[FacingDirection.UpRight];
return "up";
return _directionsTable[FacingDirection.Up];
}
private readonly Dictionary<FacingDirection, string> _directionsTable = new()
{
{ FacingDirection.Right, "right" },
{ FacingDirection.Left, "left" },
{ FacingDirection.Up, "up" },
{ FacingDirection.Down, "down" },
{ FacingDirection.UpLeft, "up_left" },
{ FacingDirection.UpRight, "up_right" },
{ FacingDirection.DownLeft, "down_left" },
{ FacingDirection.DownRight, "down_right" }
};
private enum FacingDirection
{
Up,
Down,
Left,
Right,
UpRight,
UpLeft,
DownRight,
DownLeft
}
}