Topic was automatically imported from the old Question2Answer platform.
Asked By
royinlove
Good evening,
I’m Roy, and a friend recommended Godot to me a week ago and since then I’m hooked on it.
I’ve been working on my 2d project a lot and I’ve got an attack animation which doesn’t seem to want to make my life easy.
I want to be able to press the CTRL button and let my AnimatedSprite do the whole Attack animation , even if I’m walking (by Input.is_action_pressed(“ui_right \ left”) ) and trying to trigger the walk animation.
How can I do that?
Or does anyone have a demo project I can learn from?
Add a condition before playing the walk animation, where you check wether or not the attack animation is playing and if it is, just don’t play the walk animation, until the attack animation is finished.
Or use 2 diffrent animatedSprites for the movement and attack and let function together or alone, like Mario moving his legs for running and throwing a fireball with his hand, allà Super Mario World.
Ok, so the way I solved this problem was by using
Input.is_action_just_pressed(“ui_x”)
to change the state of a variable “is_attacking”.
This is placed within the main input “if” statement as an elif. I then have another elif check if “is_attacking” is true, and if it is, play the attack animation.
I then connect a signal for Animation_Finished from the AnimatedSprite to the Character’s Script, and inside the function that’s made, ensure that “is_attacking” is made false.
So, back in my physics_process, “is_attacking” will be true for one full animation cycle of the attack animation, and the animation stops after that.
Here’s the code that I used. Declare a var is_attacking outside of the process :
Now I’m having trouble if I move while attacking it interrupts the animation and after the move animation plays it replays the attack animation until it’s complete.
Note, I am totally new to this and made it a goal to setup the move, idle, jump, fall and attack animations from scratch and need to implement motion now.