0 votes

So I have 2 animations one for shooting and one for walking but if I shoot while I'm walking the shooting animation does not play (the sound does play). This is the code triggers the animations.enter image description hereAnd this is the code that has the shooting and walking functions.

enter image description here

I want the walking animation stop and let the shooting animation play then continue the walking animation if the player is still holding down a moving button.

Godot version Godot 3.5.1
in Engine by (12 points)
edited by

1 Answer

0 votes

Image #1

Welcome to the wonderful world of programming.

In your above code every if will be tested and every one to be true will be executed in terms of animation that will be the last one to be shown

What you're looking for is called an elif conditional statement that must follow an if block
It basically means else if

if a:
elif b:
elif c:

And what happens during execution is if thea condition is false then the b condition is tested and so on until the last elif or else

Image #2

var last_move_pos = 0

func shoot():
    if AnimPlayer.is_playing():
        last_move_pos = AnimPlayer.get_current_animation_position()


func move():
    if AnimPlayer.is_playing():

With more animations and more complex blending it would be better to use an AnimationTree

by (6,876 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.