Godot 4.2.2
So I’m just starting my journey in game development and I’ve been following Brackeys tutorial on youtube. We are making a simple platform game with Godot and so far it has been going great. I made a couple typo mistakes earlier in my code but was able to diagnose them and correct. But now I’ve gotten to the part where we added a few lines of code to flip my animated sprite 2d and I followed the steps to the letter. The only problem is it does NOTHING. It doesn’t give me an error message or crash the game or anything which is good. But it may as well not exhist in the script because it literally doesn’t do anything. It’s supposed to flip my sprite to the left and right when I’m going in those directions. Can anyone see where I went wrong??
extends CharacterBody2D
const SPEED = 130.0
const JUMP_VELOCITY = -300.0
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var animated_sprite = $AnimatedSprite2D
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction: -1, 0, 1
var direction = Input.get_axis("move_left", "move_right")
# Flip the sprite
if direction > 0:
animated_sprite.flip_h = false
elif direction > 0:
animated_sprite.flip_h = true
# Applies movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()