![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Samki |
Hello im currently practicing on how to use godot and im working on a simple platformer but my running animation only plays one frame and the running animation plays when i jump heres my code below
extends KinematicBody2D
Defining Variables for movement and gravity
export (int) var gravity = 4000
export (int) var speed = 200
export (int) var jump_speed = -1000
Movement for button pressed
var velocity = Vector2.ZERO
onready var animation = $AnimatedSprite
func _physics_process(delta):
velocity.x = 0
if velocity.y == 0 and velocity.x == 0:
if is_on_floor():
animation.play("idle")
if Input.is_action_pressed("move_right"):
velocity.x = speed
if is_on_floor():
animation.play("run_animation")
animation.flip_h = false
if Input.is_action_pressed("move_left"):
velocity.x -= speed
if is_on_floor():
animation.play("run_animation")
animation.flip_h = true
velocity.y += gravity * delta
velocity = move_and_slide(velocity,Vector2.UP)
if Input.is_action_just_pressed("jump"):
if is_on_floor():
velocity.y = jump_speed