+3 votes

I'm hoping for some help or direction with setting up animations for a fps(like hand movement or weapon movements). I've tried to just play the animation when the wsad keys where being pressed but it didn't work because it just kept re-starting the animation. i'm new to GDScript and I've found no useful info on the subject, this is my last resort. :(

in Engine by (81 points)

2 Answers

+1 vote
Best answer

Try playing the animation only once when starting to move, using a variable. Something like:

var should_play_anim = true

func _fixed_process(delta):
    if not Input.is_action_pressed("move_forwards"):
        get_node("AnimationPlayer").stop()
        should_play_anim = true

    if Input.is_action_pressed("move_forwards") and should_play_anim:
        get_node("AnimationPlayer").play("walk")
        should_play_anim = false

(Note that this code has not been tested.)

by (11,893 points)
selected by

if you wanted to add an attack animation could you just add to the function something like this?

if Input.ismousebuttonpressed(1):
get
node("AnimationPlayer").play("fire")
"play some sound"

0 votes
    if (Input.is_action_pressed("up")):#checks for up button pressed
      if(not THE_ANIMATION_PLAYER.get_current_animation()=="WALK_CYCLE"):
      #check if playing move forward animation prevemts aniamtion flickering
      THE_ANIMATION_PLAYER.play("WALK_CYCLE",0.5,1.5,false )
      #playing move forward animation
by (440 points)
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.