Movement refactor

This commit is contained in:
2025-08-30 23:06:12 +02:00
committed by GitHub
parent d786ef4c22
commit 88c7a0a055
41 changed files with 656 additions and 122 deletions

View File

@@ -0,0 +1,40 @@
using Godot;
namespace Mr.BrickAdventures.scripts.components;
[GlobalClass]
public partial class SpriteTilterComponent : Node
{
[Export] public Node2D RotationTarget { get; set; }
[Export(PropertyHint.Range, "0,45,1")] public float MaxTiltAngle { get; set; } = 10.0f;
private CharacterBody2D _body;
public override void _Ready()
{
_body = GetOwner<CharacterBody2D>();
if (_body == null)
{
GD.PrintErr("SpriteTilterComponent must be a direct child of a CharacterBody2D.");
SetProcess(false);
}
if (RotationTarget == null)
{
GD.PrintErr("SpriteTilterComponent needs a RotationTarget to be set in the inspector.");
SetProcess(false);
}
}
public override void _Process(double delta)
{
var targetAngleRad = 0.0f;
var horizontalVelocity = _body.Velocity.X;
if (horizontalVelocity > 0.1f)
targetAngleRad = -Mathf.DegToRad(MaxTiltAngle);
else if (horizontalVelocity < -0.1f) targetAngleRad = Mathf.DegToRad(MaxTiltAngle);
else targetAngleRad = 0.0f;
RotationTarget.Rotation = targetAngleRad;
}
}