This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

important: I'am using AnimatedSprite
I made animation via documentation godot link:
but in with documentation do only animation run if you input key right and stop animation but i wanna if you not input any key: animations idle
my code:

extends KinematicBody2D

onready var _animated_sprite = $AnimatedSprite

func _process(_delta):
    if Input.is_action_pressed("ui_down"):"run")
    elif Input.is_action_pressed("ui_up"):"run")
    elif Input.is_action_pressed("ui_left"):"run")
    elif Input.is_action_pressed("ui_right"):"run")

(I'm add keys up, down and left)
thanks for help <3!

Godot version 3.5.1
in Engine by (21 points)
edited by

Edited to fix code formatting...

1 Answer

0 votes

That else block will execute if none of the 4 input keys are being pressed, so you could replace this:


With something like:

if !_animated_sprite.playing():"idle")
by (22,704 points)

what if i am using animation player, every animation work properly but not the attack, it only show millisecond of the animation and then return to idle animation
here is the code:

extends KinematicBody2D

var velocity : Vector2

export var max_speed : int = 600
export var gravity : float = 35
export var jump_force : int = 1600
export var acceleration : int = 50
export var jump_buffer_time : int  = 15
export var cayote_time : int = 15

var jump_counter : int = 0
var jump_buffer_counter : int = 0
var cayote_counter : int = 0

func _physics_process(_delta):

if is_on_floor():
    cayote_counter = cayote_time
    jump_counter = 0

if not is_on_floor():
    if cayote_counter > 0:
        cayote_counter -= 1

if jump_buffer_counter > 0 and jump_counter < 1:
    jump_counter += 1
    cayote_counter = 1

velocity.y += gravity
if velocity.y > 2000:
    velocity.y = 2000

if Input.is_action_pressed("right"):
    velocity.x += acceleration 
    $Sprite.flip_h = false
elif Input.is_action_pressed("left"):
    velocity.x -= acceleration
    $Sprite.flip_h = true
elif Input.is_action_pressed("jump"):
elif Input.is_action_just_pressed("attack"):
    velocity.x = lerp(velocity.x,0,0.2)

velocity.x = clamp(velocity.x, -max_speed, max_speed)

if Input.is_action_just_pressed("jump"):
    jump_buffer_counter = jump_buffer_time

if jump_buffer_counter > 0:
    jump_buffer_counter -= 1

if jump_buffer_counter > 0 and cayote_counter > 0:
    velocity.y = -jump_force
    jump_buffer_counter = 0
    cayote_counter = 0

if Input.is_action_just_released("jump"):
    if velocity.y < 0:
        velocity.y += 400

velocity = move_and_slide(velocity, Vector2.UP)

func attack_detected():

func attack():

func _on_AttackBox_body_entered(body):
if body.has_method('attacked'):
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.