How do I change the my character animation when my player picks up something?

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

hi! im new to godot so please help. So basically i have a character animation that isn’t wearing a mask but if that player picks up a mask i want it to change the character animation that is wearing one.

:bust_in_silhouette: Reply From: Magso

If you’re using an animated sprite go to the SpriteFrames tab on the bottom, go to the left side and you can make a number of animations for the SpriteFrame resource and switch between them using AnimatedSprite.set_animation("animation name")

Oh sorry the info i gave was vague, im using an animationplayer and animationtree.
In my Animation Tree i made 4 roots which is Idle, Run, Facemaskidle, Facemaskrun.
while in the pickable item facemask i use an animated sprite for it.
currently the script inside the facemask is this:

extends Area2D

func _on_facemask_body_entered(body):


which makes the facemask disappear when a player walk towards it

Iskailf | 2020-11-19 15:03

In the roots, the FacemaskIdle and FacemaskRun are the player sprites i made so when he comes on contact or collects the facemask it would switch to those animation instead of Idle and Run which is the Character that has no facemask on. i hope you get my idea
this is the code for my player:

func _physics_process(_delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength(“right”) - Input.get_action_strength(“left”)
input_vector.y = Input.get_action_strength(“down”) - Input.get_action_strength(“up”)
input_vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
	animationTree.set("parameters/Idle/blend_position", input_vector)
	animationTree.set("parameters/Run/blend_position", input_vector)"Run")
	velocity = velocity.move_toward(input_vector * SPEED, ACCELERATION * _delta)
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * _delta)

velocity = move_and_slide(velocity)

func facemask_wear():
facemask = facemask + 1
print(“I have a facemask”)

Iskailf | 2020-11-19 15:08

if facemask is an int you can use a match statement

match facemask:
        #normal animations
        #mask animations

Magso | 2020-11-19 18:07