So i am trying to play the “Jab” animation whenever I press the J key (the one I use for jabbing) the character just shakes like if he is going to jab. I know my code is not the cleanest lol! KingGD the best is helping me on cleaning it out, but for now here is a video of what is happening and also the code.
Thanks,
#Variable for the Player Walking Speed.
@export var speed = 300
#Variable for the AnimatedSprite to use for flip etc.
@onready var adam_animated_sprite = $AnimatedSprite2D
#Jabbing variable.
@export var jabbing = false
#This code controls the up, down, right and left of the Character.
func _process(delta: float) -> void:
var direction = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
velocity = direction * speed
move_and_slide()
# This is and if that calls a function below for jabbing
if Input.is_action_just_pressed("Jab"):
jab()
#This code is to Flip the Character and playes the animation for walking, Jabbing.
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("ui_left"):
adam_animated_sprite.flip_h = true
adam_animated_sprite.play("Walking")
elif Input.is_action_pressed("ui_right"):
adam_animated_sprite.flip_h = false
adam_animated_sprite.play("Walking")
elif Input.is_action_pressed("ui_up"):
adam_animated_sprite.play("Walking")
elif Input.is_action_pressed("ui_down"):
adam_animated_sprite.play("Walking")
else:
adam_animated_sprite.play("Idle")
func jab():
jabbing = true
adam_animated_sprite.play("Jab")```
Here is the video!
![Recording 2024-11-10 131801|video](upload://7vwFYr78466dLBfsxfAc4kLMdnH.mp4)
@KingGD got thru he helped clean my code and help with the jabbing issue! now onto why is jabbing slow! the jab is a start of a combo, but your solution was correct!!!
#Variable for the Player Walking Speed.
@export var speed := 300
#Variable for the AnimatedSprite to use for flip etc.
@onready var adam_animated_sprite = $AnimatedSprite2D
#Jabbing variable.
@export var jabbing := false
#This code controls the up, down, right and left of the Character.
func _process(delta: float) -> void:
var direction = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
velocity = direction * speed
move_and_slide()
if Input.is_action_just_pressed("Jab"):
jab()
play_animations(direction)
if direction.x: adam_animated_sprite.flip_h = true if direction.x < 0 else false
func play_animations(dir):
if jabbing:
adam_animated_sprite.play("Jab")
else:
if dir:
adam_animated_sprite.play("Walking")
else:
adam_animated_sprite.play("Idle")
func jab():
jabbing = true
await get_tree().create_timer(0.8).timeout #Attack Duration
jabbing = false```
Thank you you are right about the timer! I am a noob on gdscripting (havent code in a lot of years) searching signal animation finished!!! You all are geniuses!!!
Sorry to ask but how would I change this to be the signal animation finished? researching but I see the animation_finished has a function. Would I only need to change the timer part or the function to be _animation_finished