movement and animation script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fabius

Hello to everyone.
I have an NPC that walks forward but without the animation. Is there a mistake in the script?

extends KinematicBody2D
var movement = Vector2()
var speed = 150

func _ready():

func _process(delta):
	var velocity = Vector2()
	if velocity.x == 1:
		$RayCast2D.cast_to = Vector2(0, 50)
	var movement = 250*velocity.normalized()*delta

func update_animated_sprite(velocity):
	if velocity.x == -1:
		$AnimatedSprite.flip_h = false
	elif velocity.x == 1:
		$AnimatedSprite.flip_h = true
	elif velocity.y == -1:
	elif velocity.y == 1:
:bust_in_silhouette: Reply From: p7f

I think the problem is that you are calling $ on each process call, so animation restarts and it seems to be without animation. You shoud try for example
$AnimatedSprite.animation = "walk_down" instead.

Same for AnimationPlayer if you’re using one:
$AnimationPlayer.current_animation = 'Walk'

Dlean Jeans | 2018-12-21 06:30