Heya i’m a bit stuck with my attack animation breaking and not playing out all the way when used. and it only seems to happen when my other player animations are in the script.
Heres the code:
#flips sprite
if direction > 0:
sprite.flip_h = false
if direction < 0:
sprite.flip_h = true
if direction == 0:
animation.play("Idle")
if direction == 1:
animation.play("Run")
if direction == -1:
animation.play("Run")
if velocity.y != 0:
animation.play("Jump")
if Input.is_action_just_pressed("Attack") and sprite.flip_h == true:
animation.play("SlashLeft")
if Input.is_action_just_pressed("Attack") and sprite.flip_h == false:
animation.play("SlashRight")
if you need me to elaborate further on the problem feel free to ask.
cheers if you can help
It looks like you’re having trouble with your attack animation not playing fully when your other player animations are in the script.
From what I can see, the issue might be due to the way you’re handling your animation states. In your code, you’re checking for multiple conditions and playing different animations based on those conditions. However, if multiple conditions are true at the same time, it can cause the animation to change mid-play, which might be why your attack animation is not playing fully.
Here are a few suggestions to help you resolve this issue:
Use a state machine: Instead of checking for multiple conditions and playing animations directly, consider using a state machine to manage your animation states. This way, you can ensure that only one animation is playing at a time, and you can handle transitions between states more cleanly.
Use animation priorities: In Godot, you can set priorities for your animations. This way, if multiple animations are trying to play at the same time, the one with the higher priority will take precedence. You can use this to ensure that your attack animation takes priority over your other animations.
Use a separate function for attack animation: Instead of checking for the attack input in your main animation handling code, consider creating a separate function for handling the attack animation. This way, you can isolate the attack animation logic and ensure that it’s not affected by your other animation logic.
Here’s an example of how you could implement a state machine using an enumeration:
enum State {
IDLE,
RUN,
JUMP,
ATTACK
}
var current_state = State.IDLE
func _process(delta):
# Update state based on input and conditions
if Input.is_action_just_pressed("Attack") and (current_state == State.IDLE or current_state == State.RUN):
current_state = State.ATTACK
elif direction!= 0 and velocity.y == 0:
current_state = State.RUN
elif velocity.y!= 0:
current_state = State.JUMP
else:
current_state = State.IDLE
# Play animation based on state
match current_state:
State.IDLE:
animation.play("Idle")
State.RUN:
if direction > 0:
animation.play("Run")
else:
animation.play("Run")
State.JUMP:
animation.play("Jump")
State.ATTACK:
if sprite.flip_h == true:
animation.play("SlashLeft")
else:
animation.play("SlashRight")
Remember to adapt this example to your specific use case, and adjust the state transitions and animation logic as needed.