Godot Version
Godot 4.5.1
Question
Hello, I'm working with a student to learn Godot together. We were making a simple platformer to learn the basics. However, when trying to flip a sprite and change it's animations it simply wasn't doing anything. Here is the code.
extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
const SPEED = 100
const JUMP_VELOCITY = -200.0
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_right", "ui_left")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
print(direction)
if direction < 0:
animated_sprite_2d.flip_h = true
elif direction > 0:
animated_sprite_2d.flip_h = false
if is_on_floor():
if direction == 0:
animated_sprite_2d.play("Idle")
else:
animated_sprite_2d.play("Run")
else:
animated_sprite_2d.play("Air")
move_and_slide()
The weird part is that when I copied it into a windows instance of Godot and the code worked fine. Is there some issue with Godot on Mac, as it was originally coded on a Mac.