Brand new coder here. I recently got into Godot through a friend recommendation, and am trying to learn how to code player movements for a 2D platform game, but I am having trouble getting the player to perform a "crawl" animation.
Basically, when I try to tell the Animated Sprite to play the "crawl" animation, it only plays the first frame, and never runs the full animation like it does for all the other animations I've created.
Here is the code I've written so far. Any help would be greatly appreciated, thanks!
extends KinematicBody2D
const SPEED = 200
const CRAWLSPEED = 120
const GRAVITY = 35
const JUMPFORCE = -1100
var velocity = Vector2(0,0)
var on_ground = false
var fall = false
var crouch = false
var crawl = false
func _physics_process(_delta):
#Left/Right Logic
var axisX = Input.get_action_strength("right") - Input.get_action_strength("left")
if axisX > 0:
velocity.x = SPEED
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = false
elif axisX < 0:
velocity.x = -SPEED
$AnimatedSprite.play("walk")
$AnimatedSprite.flip_h = true
else:
$AnimatedSprite.play("idle")
#Jump Logic
if Input.is_action_pressed("jump"):
if on_ground == true:
velocity.y = JUMPFORCE
on_ground = false
if is_on_floor():
on_ground = true
else:
on_ground = false
if velocity.y > 0:
fall = true
$AnimatedSprite.play("fall")
if velocity.y < 0:
fall = false
$AnimatedSprite.play("jump")
#Crouch Logic
if Input.is_action_pressed("crouch") && on_ground == true:
crouch = true
$AnimatedSprite.play("crouch")
if crouch == true && axisX != 0:
crawl = true
$AnimatedSprite.play("crawl")
if axisX > 0:
velocity.x = CRAWLSPEED
$AnimatedSprite.flip_h = false
elif axisX < 0:
velocity.x = -CRAWLSPEED
$AnimatedSprite.flip_h = true
else:
crawl = false
else:
crouch = false
#Velocity Logic
velocity.y = velocity.y + GRAVITY
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = lerp(velocity.x,0,0.1)