#I have problem with animation Player

5 messages · Page 1 of 1 (latest)

wild cradle
#

i made jump animaiton it is working when i only press space
but when i press jump and s or a the animation of jump and walk is mixed up

#
extends CharacterBody2D

@export var speed = 400
@export var jump_speed = -1000
@export var gravity = 4000

func _physics_process(delta):
    # Add gravity every frame
    velocity.y += gravity * delta

    # Input affects x axis only
    velocity.x = Input.get_axis("left", "right") * speed

    move_and_slide()

    # Only allow jumping when on the ground
    if Input.is_action_just_pressed("jump") and is_on_floor():
        velocity.y = jump_speed
        get_node("AnimationPlayer").play("jump")
    if Input.is_action_pressed("left"):
        get_node("AnimationPlayer").play("run_left")
    if Input.is_action_pressed("right"):
        get_node("AnimationPlayer").play("run_right")
    if velocity.x == 0.0 and velocity.y == 0.0:
        get_node("AnimationPlayer").play("idle")
#

i searched the problem in google and shows about yeild but godot 4.0 has await and i dont know how to use it

soft wing
#

if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_speed
get_node("AnimationPlayer").play("jump")
elif Input.is_action_pressed("left"):
get_node("AnimationPlayer").play("run_left")
elif Input.is_action_pressed("right"):
get_node("AnimationPlayer").play("run_right")
elif velocity.x == 0.0 and velocity.y == 0.0:
get_node("AnimationPlayer").play("idle")

#

change the last 3 If to elif