u/Firm_Vegetable1964

▲ 3 r/GodotEngine+1 crossposts

https://reddit.com/link/1suz392/video/i489q6h3u8xg1/player

So, I have this character with a walk animation and a default animation, but at "random" moments, the animations start switching between them until I turn around. I've tried several solutions, and none of them work. Here's my character code (it's in Spanish):

extends CharacterBody2D

u/onready var ray_suelo = $RayCast2D

var doble_salto:int = 2

const SPEED = 550.0

const JUMP_VELOCITY = -550.0

var velocidad_minima = 0.1

u/onready var animaciones = $AnimatedSprite2D

func _ready():

animaciones.play("default")

func _physics_process(delta: float) -> void:

\# gravedad

if not is\_on\_floor():

	velocity += (get\_gravity() \* delta)



if GameManager.vida <= 0:

	get\_tree().change\_scene\_to\_file("res://etc/perdiste.tscn")



\# reset salto

if is\_on\_floor():

	doble\_salto = 2



\# salto (SIN animación acá)

if Input.is\_action\_just\_pressed("ui\_accept"):

	if is\_on\_floor():

		velocity.y = JUMP\_VELOCITY

		doble\_salto -= 1

	elif doble\_salto > 0:

		velocity.y = JUMP\_VELOCITY

		doble\_salto -= 1



var direction := Input.get\_axis("a", "d")



if direction != 0:

	velocity.x = direction \* SPEED

	animaciones.flip\_h = direction < 0

	if is\_on\_floor():

		animaciones.play("walk")

else:

	velocity.x = move\_toward(velocity.x, 0, SPEED)

	if is\_on\_floor():

		animaciones.play("default")



move\_and\_slide()



\# animación de salto (al final)

if not is\_on\_floor():

	animaciones.play("jump")
reddit.com
u/Firm_Vegetable1964 — 2 months ago