+1 vote

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.

in Engine by (13 points)

1 Answer

0 votes

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")

by (3,225 points)

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 onfacemaskbodyentered(body):
body.facemask_wear()

queue_free()

which makes the facemask disappear when a player walk towards it

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 physicsprocess(delta):
var input
vector = Vector2.ZERO
inputvector.x = Input.getactionstrength("right") - Input.getactionstrength("left")
input
vector.y = Input.getactionstrength("down") - Input.getactionstrength("up")
inputvector = inputvector.normalized()

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


velocity = move_and_slide(velocity)

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

if facemask is an int you can use a match statement

match facemask:
    0:
        #normal animations
    1:
        #mask animations
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.