Godot Version
4
Question
Can anyone help me? My game is a mobile game and it uses touchscreen controls. I've coded an 'idle' and 'walk' animation and it works perfectly. However, the 'run' animation only plays the first frame. (The 'run' animation will only be executed if the 'right'/'left' and the 'running' button pressed ad the same time)
My code :
extends CharacterBody2D
func _ready():
pass
func _process(delta):
if Input.get_action_strength(“left”):
walkleft(delta)
elif Input.get_action_strength(“right”):
walkright(delta)
else:
$AnimatedSprite2D.play(“Idle”)
if Input.get_action_strength("Run") and Input.get_action_strength("left"):
runleft(delta)
elif Input.get_action_strength("Run") and Input.get_action_strength("right"):
runright(delta)
else:
$AnimatedSprite2D.play("idle")
func walkleft(delta):
$AnimatedSprite2D.scale.x = -1
$AnimatedSprite2D.play(“walk”)
position.x -= 185 * delta
func walkright(delta):
$AnimatedSprite2D.scale.x = 1
$AnimatedSprite2D.play(“walk”)
position.x += 185 * delta
func runleft(delta):
$AnimatedSprite2D.scale.x = -1
$AnimatedSprite2D.play(“run”)
position.x -= 185 * delta
func runright(delta):
$AnimatedSprite2D.scale.x = 1
$AnimatedSprite2D.play(“run”)