Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | yhackall |
I can’t make my jump animation active. I understand that it is because my main motion animation is still working.
I achieved my goal by modifying the code in this way
func _ready():
$jump_anim.hide()
if is_on_floor():
$AnimatedSprite.show()
$AnimatedSprite.playing
$jump_anim.hide()
$jump_anim.stop()
if jump:
velocidad.y = jump_power
$jump_anim.show()
$jump_anim.play("jump")
$AnimatedSprite.hide()
$AnimatedSprite.stop()
but there are times when the animation does not end correctly, which causes the button to skip the animation again to start the last time and so on.
I tried to do it in other ways but I don’t get it to work or just start the first frame.
This is the whole code, I hope you give me a hand with this: D
extends KinematicBody2D
const movimiento = 500
const gravedad = 1500
const jump_power = -650
var velocidad = Vector2()
func _physics_process(delta):
var walk_left = Input.is_action_pressed("ui_left")
var walk_right = Input.is_action_pressed("ui_right")
var jump = Input.is_action_pressed("ui_up")
var jump_stop = Input.is_action_just_released("ui_up")
var on_wall = $CollisionShape2D/RayCast2D.is_colliding();
if walk_left:
if on_wall and $AnimatedSprite.flip_h and not is_on_floor():
velocidad.y = jump_power
velocidad.x = -movimiento
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("izquierda")
$CollisionShape2D/RayCast2D.rotation_degrees = 270
elif walk_right:
if on_wall and not $AnimatedSprite.flip_h and not is_on_floor():
velocidad.y = jump_power
velocidad.x = movimiento
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("izquierda")
$CollisionShape2D/RayCast2D.rotation_degrees = 90
else:
velocidad.x = 0
$AnimatedSprite.play("quieto")
if is_on_floor():
if jump:
velocidad.y = jump_power
elif jump_stop and velocidad.y < 0:
velocidad.y *= 0.5
velocidad.y += gravedad * delta
velocidad = move_and_slide(velocidad, Vector2(0, -1))