Godot 4.3
I’m making a 2D platformer where you are a bipedal cat that climbs through various levers. I made the sprites I want for my animations on a sprite sheet but I’m having problems with getting the jump animation working properly. For some reason it works well when I jump but when I touch the ground and I’m still holding a move button I will be locked in the jump animation until I release the button which will put me in the still animation. I don’t know how to code well so from as far as I know my logic seems foolproof but I seem to be proven wrong with every new idea I try. I also want to add a still animation that faces to the left. I currently only know how to make a general still animation and it faces right so if you can help with that that would be appreciated. I really appreciate anybody who can help with this. I will gladly add further details if nessicary
the code
extends CharacterBody2D
const SPEED = 8000.0
const JUMP_VELOCITY = -15000.0
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
func _ready ():
Input. set_mouse_mode (Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta: float) → void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta * 30
if Input. is_action_just_pressed(“quit”):
get_tree().quit()
if Input.is_action_just_pressed(“jump”):
animated_sprite_2d.play(“jump_right”)
if Input.is_action_just_pressed(“left”):
animated_sprite_2d.play(“walk_left”)
if Input.is_action_just_pressed(“right”):
animated_sprite_2d.play(“walk_right”)
# Handle jump.
if Input.is_action_just_pressed("jump") 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("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
animated_sprite_2d.play("still_right")
move_and_slide()