I'm new to Godot and following Brackey's Tutorial on how to get started. After I finished it, I started editing it and adding new tutorials. Today, halfway through editing the coin script, my player character stopped moving entirely. Not moving left, right, or falling with the gravity that was previously made at the beginning of the tutorial. I am at a loss, and this may be because I'm new to Godot, but I can't seem to fix it no matter what solution I try. It feels like I'm going in circles. The Player consists of a CharacterBody2D, with an AnimatedSprite2D node and a CollisionShape2D node. The movement script is as follows:
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
# Play animations
if is_on_floor():
if direction == 0:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
# Apply movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
While I don't believe the script is the problem, I think it has something to do with how the code works. Thank you for your time!