How can I change the animation on KinematicBody2D?

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

I’m trying to change the animation, like this (but it’s going wrong):

  onready var raycasts = $raycasts

   func _set_animation():
var anim = "Idle"

if !is_grounded:
	anim = "Jump"
elif velocity.x != 0:
	anim = "Run"

if $anim.assigned_animation != anim:
	$anim.play(anim)
:bust_in_silhouette: Reply From: Waffle_32

Use this metod(.animation metod), for example:

$anim.animation = "Idle" 

So, this code example can be usefull for you:

func _process(delta): # USE THE FUNCTION YOU LIKE
   if !is_grounded:
      $anim.animation = "Jump"
   elif velocity.x != 0:
      $anim.animation = "Run"

I hope it works for you! =)