Topic was automatically imported from the old Question2Answer platform.
Asked By
1997
Old Version
Published before Godot 3 was released.
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.
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.)
if you wanted to add an attack animation could you just add to the function something like this?
if Input.is_mouse_button_pressed(1):
get_node(“AnimationPlayer”).play(“fire”)
“play some sound”
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