Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Fabius |
Hello to everyone.
I have an NPC that walks forward but without the animation. Is there a mistake in the script?
Thanks!
extends KinematicBody2D
var movement = Vector2()
var speed = 150
func _ready():
pass
func _process(delta):
var velocity = Vector2()
move_and_collide(Vector2(0,+1))
if velocity.x == 1:
$RayCast2D.cast_to = Vector2(0, 50)
var movement = 250*velocity.normalized()*delta
self.move_and_collide(movement)
self.update_animated_sprite(velocity)
func update_animated_sprite(velocity):
if velocity.x == -1:
$AnimatedSprite.flip_h = false
$AnimatedSprite.play('walk_left')
elif velocity.x == 1:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play('walk_left')
elif velocity.y == -1:
$AnimatedSprite.play('walk_up')
elif velocity.y == 1:
$AnimatedSprite.play('walk_down')