The current system applies a scale transformation to the CharacterBody2D when the current horizontal velocity is more or less than 0 based off of the current pressed input keys. This should work in theory, and by all means it should work. I have even tried isolating the movement of the character and the change in direction, with no avail.
When run, the D/right arrow key always faces the character to the right as it is supposed to. However, the A/left arrow causes it to constantly flip between facing left and facing right.
using Godot;
public partial class CharacterController : CharacterBody2D
{
[Export]
public int Speed { get; set; } = 100;
private Vector2 velocity = new Vector2(0, 0);
public void InputHandler()
{
Vector2 input_direction = Input.GetVector("move_left", "move_right", "move_up", "move_down");
velocity = input_direction * Speed;
GD.Print(input_direction);
if (input_direction.X < 0) // Left
{
ApplyScale(new Vector2(-1, 1));
}
else if (input_direction.X > 0) // Right
{
ApplyScale(new Vector2(1, 1));
}
}
public override void _PhysicsProcess(double delta)
{
InputHandler();
var collision_info = MoveAndCollide(velocity * (float)delta);
if (collision_info == null)
{
MoveAndSlide();
}
}
}