Topic was automatically imported from the old Question2Answer platform.
Asked By
FranticButter
Whenever I press my movement key it doesn’t play the walking animation loop and stays on the idle animation. If anything it will only play the first frame.
Here is my movement script:
extends KinematicBody2D
var is_moving = false
var motion : = Vector2()
const MOVE_SPEED : = 150
func _physics_process(delta):
#move script
if Input.is_action_pressed("left"):
motion.x = -MOVE_SPEED
is_moving == true
elif Input.is_action_pressed("right"):
motion.x = MOVE_SPEED
is_moving == true
else:
motion.x = 0
is_moving == false
#this makes the move script work bro
motion = motion.normalized() * MOVE_SPEED
motion = move_and_slide(motion)
#animation container... contains animations.
func _process(delta):
if is_moving == false:
$AnimatedSprite.play("idle")
if is_moving == true:
$AnimatedSprite.play("walking")
have a fail in your code. when your press a key to move the “is_moving” var not change to true. because your still comparing using “==” to set the value you need to use a single equals sign.
Your problem is that when you set is_moving, you use two equal signs. That is a comparison, just use one when setting a value. The code below is the same as yours but I just changed the equals signs where you need them. Hopefully this helps, if not, just ask and I can try and help you!
extends KinematicBody2D
var is_moving = false
var motion : = Vector2()
const MOVE_SPEED : = 150
func _physics_process(delta):
#move script
if Input.is_action_pressed("left"):
motion.x = -MOVE_SPEED
is_moving = true
elif Input.is_action_pressed("right"):
motion.x = MOVE_SPEED
is_moving = true
else:
motion.x = 0
is_moving = false
#this makes the move script work bro
motion = motion.normalized() * MOVE_SPEED
motion = move_and_slide(motion)
#animation container... contains animations.
func _process(delta):
if is_moving == false:
$AnimatedSprite.play("idle")
if is_moving == true:
$AnimatedSprite.play("walking")
It worked! Thanks so much. I can’t believe I’ve believed for so long that it meant it was setting it equal to true.