How to make a melee attack, such as a sword swing or punch. Art by Elthen: elthen.itch.io/ Text version: godotrecipes.com/3.x/animation... Support me on Patreon: / kidscancode
My animation was refusing to play all the way even when I had the playtime longer than the animation. This tutorial fixed everything and now my character is looking spicy
thanks all the other videos i tried to watch on this made the whole process really complicated, when i just needed to make area2s a child of the sprite. i really appreciate this vide.
those sprites look pretty damn good I must say, thank you for your work good sir, I've been following you since the python days. I wouldn't say your content is really for young children but as a 30 year old dude I enjoy it.
Thank you for your tutorials. I wasn't able to find information about "advanced condition" in state machine transition. Is there any way I can do that?
In case animation and movesets are far more complex than in this case, would it be advisable to have the whole animation part be handled by a different scene that receives input from the player through the character scene?
This would've been really useful when I was coding that - I think I ended up doing something like making a fireball and setting the velocity to zero then animating a sword instead
I know this is an old tutorial now. But, just watched it now. It isn't that useful without an explanation of how to put the Group together to make it work. I tried all the suggestions in the comments, and none of them worked. That said, I still appreciate taking the time to make this tutorial.
Hello, I need help. Could you help me to put an enemy character which I can attack and he will die ? I could not do it. I created my character but I could not set collasion.
Everything has been super helpful, but I can't figure out how to set up the hurtbox on the enemy's node to talk with the player node. Can anybody help me?
Thanks, I watched your video and I see that you implement an AnimationPlayed and a basic Sprite, I ask you, how could I do the same using an AnimatedSprite? I already have several animations that way, but I can't find a way to integrate what you do with what I have.
You can't do this with AnimatedSprite. The AnimationTree state machine works by controlling AnimationPlayer nodes. AnimatedSprite is not very sophisticated - it's a much simpler form of animation.
I got stuck on trying to get the Area2D's collision box to flip when the character turns around. I was already using flip_h on my character's sprite in my movement script (I'm using a different method than yours here), but my hitbox won't flip even though my sprite does. So how can I easily get it to flip without redoing my whole movement code?
I think you'll have to change scale through code. You don't have to re-write your entire code, you only have to add new lines where your character movement is. I'm also stuck on a problem like yours.
I found a way to fix it! The code is: $Sprite.scale.x = -1 ( if your character is moving to the left) and $Sprite.x = 1 (if your character is moving to the right) Try to add that to your script
i do have one issue with this setup, with characters that do melee damage with a weapon, you can't just flip or scale -1 them, you need a different animation for them to keep using the same hand, i know a lot don't care about this, but i do, it's some extra work, and it's even worth it even though 9/10 don't see it or at least call it out, but i bet you that 5/10 will call it out if you don't care about this
That is how the `area_entered` signal is supposed to work. If you want to continuously check, use a variable to keep track of the body when it enters, and then reset that variable when it leaves.
I got something like this working, there's one huge oversight that this video didn't mention for the latest version of Godot. Using -1 on the Animated Sprite scale does NOT flip the hurtbox horizontally. Neither does flip_h on the Sprite node. As far as I can see, you have to make a hurtbox for the left and right facing attacks, running a check to see of the Animated Sprite is flipped and enabling the corresponding hurtbox . Everything else is spot on, just baffled but taking this hacky shortcut that no longer works in Godot 3.1.
@@Kidscancode Whoops, I used a Node instead of a Node 2D and didn't realize that Nodes don't have transform information, but Node 2Ds do. I think that should be mentioned in this video.
Emaleth very true, however the animation player adds the convenience of seeing exactly when something will occur in an animation and being able to easily edit it for new animations aswell. I used to use the timer method myself and I hate myself for it now because this is so much easier XD
@@minebrostj1430 yes, but if you like me have already player done and then you want to add melee, well... for me at least, as a beginner, it was simpler.
@@Kidscancode I solved my problem; getting variables from the said area 2D since the damage dealing function is interacting with the area 2D; I found a way to pass the info to the main body of the player.
I don't know how you did it. There was no collision trigger on my version (3.1.1), so I submitted a bug. If you can provide a Godot project demo, I'll see if I missed anything. github.com/godotengine/godot/issues/28803
4 Seconds in and he already faces you with your biggest problems...
10/10 Straight forward
I absolutely love that
Good lord, the power of the AnimationPlayer. It's simply amazing
Keep up the great work, Chris! The Godot community is lucky to have you!
I've been grappling with this for two days and you solved it in 5 minutes and 18 seconds. Thanks!
You are a life saver for showing the actual collision shapes! I just realized my coding issue!
Can you show us the code for the hurtbox and how to set that up?
My animation was refusing to play all the way even when I had the playtime longer than the animation. This tutorial fixed everything and now my character is looking spicy
Thank you so much, this is the type of tutorials that UA-cam needs.
thanks all the other videos i tried to watch on this made the whole process really complicated, when i just needed to make area2s a child of the sprite. i really appreciate this vide.
Your godot tutorial videos are the literal best. I appreciate your work so much. Thank you!
Good tutorial with good content in only 5 minutes. I really enjoy this tutorial thank you.
Thanks for quick and clean tutorials
This answered a lot of my question,thanks
I vastly underestimated the power of animation player when I first started using Godot... wish I had this video back then
those sprites look pretty damn good I must say, thank you for your work good sir, I've been following you since the python days. I wouldn't say your content is really for young children but as a 30 year old dude I enjoy it.
Thank you for your tutorials. I wasn't able to find information about "advanced condition" in state machine transition. Is there any way I can do that?
Wow, I wish I knew about this before I started my attack code. Thanks for the tutorial!
In case animation and movesets are far more complex than in this case, would it be advisable to have the whole animation part be handled by a different scene that receives input from the player through the character scene?
cool idea, waiting for more recipes!
I've already added more on the site, just haven't had a chance to record them yet!
This would've been really useful when I was coding that - I think I ended up doing something like making a fireball and setting the velocity to zero then animating a sword instead
this channel is a god send! thank you!
ps. some requests i have for tutorials - a dialogue system and a turn based rpg :)
GDQuest has both of those! ua-cam.com/channels/xboW7x0jZqFdvMdCFKTMsQ.html
could we possibly get these updated to the newest versions?
I know this is an old tutorial now. But, just watched it now. It isn't that useful without an explanation of how to put the Group together to make it work. I tried all the suggestions in the comments, and none of them worked. That said, I still appreciate taking the time to make this tutorial.
so what would the code for the barrel be- how do the barrel register that it has been hurt?
How did you made the dummy (barrel)?
hey man! thanks for all of your work
ua-cam.com/play/PLsk-HSGFjnaFOLHUcZFHD988Wg39rkopw.html
ua-cam.com/play/PLsk-HSGFjnaFwmOFrfD4gQQqvgvEUielY.html
Hello, I need help. Could you help me to put an enemy character which I can attack and he will die ? I could not do it. I created my character but I could not set collasion.
How to make hurt box?
How to do with the character's weapon separate?
how do we get the sprite into the animationplayer?
Everything has been super helpful, but I can't figure out how to set up the hurtbox on the enemy's node to talk with the player node.
Can anybody help me?
the wat to do it is putting the "hurtbox" tag on the area2D (that is parent) of the collishion shape you want to detect
How can I do it for the opposite side? :(
I have the same problem :( Can you solve it?
Can you do how to do a fighter game next or at some point? Also, looking forward to new recipes.
Very nice and simple
This doesn't seem to work with the animatedSprite note; right? I was trying but could not figure it out....
Thanks, I watched your video and I see that you implement an AnimationPlayed and a basic Sprite, I ask you, how could I do the same using an AnimatedSprite? I already have several animations that way, but I can't find a way to integrate what you do with what I have.
You can't do this with AnimatedSprite. The AnimationTree state machine works by controlling AnimationPlayer nodes. AnimatedSprite is not very sophisticated - it's a much simpler form of animation.
Put some ads on your videos, I'll gladly watch them. I can't support anyone on Patreon right now.
Thank you so much
Can somebody help me when I run and start attacking it says "nonexistent function in _group in base Area2D ?
The function name is "is_in_group()"
I got stuck on trying to get the Area2D's collision box to flip when the character turns around. I was already using flip_h on my character's sprite in my movement script (I'm using a different method than yours here), but my hitbox won't flip even though my sprite does. So how can I easily get it to flip without redoing my whole movement code?
I think you'll have to change scale through code. You don't have to re-write your entire code, you only have to add new lines where your character movement is. I'm also stuck on a problem like yours.
I found a way to fix it! The code is: $Sprite.scale.x = -1 ( if your character is moving to the left) and $Sprite.x = 1 (if your character is moving to the right) Try to add that to your script
I'm having trouble to do it in 3d :( guess I'll go back to 2d..
how do you do this with the AnimatedSprite node?
You couldn't use this technique with AnimatedSprite, as it only controls the displayed texture. AnimationPlayer is capable of much more than that.
i do have one issue with this setup, with characters that do melee damage with a weapon, you can't just flip or scale -1 them, you need a different animation for them to keep using the same hand, i know a lot don't care about this, but i do, it's some extra work, and it's even worth it even though 9/10 don't see it or at least call it out, but i bet you that 5/10 will call it out if you don't care about this
excellent.
great tutorial..
oh lord im so stupid, ive been using timer to match my animation with the collision shape hide/show when it could be so much easier. i hate myself
Well the worst part about learning an game engine and programming are all those possibilitys you didnt even think of :D
I enjoy your tutorials. They are extremely helpful. Are there sample file available for the project on github?
Not really, as this was a mishmash of a project that I made to demonstrate a few different things.
@@Kidscancode Thank you for replying
how do you do it with 3d?
In pretty much the same way. Use Area instead of Area2D, etc.
I have a problem with using signals, the problem is that they only emit the signal once they enter an area and not while in the area. Any solutions?
That is how the `area_entered` signal is supposed to work. If you want to continuously check, use a variable to keep track of the body when it enters, and then reset that variable when it leaves.
@@Kidscancode oh thanks
I got something like this working, there's one huge oversight that this video didn't mention for the latest version of Godot. Using -1 on the Animated Sprite scale does NOT flip the hurtbox horizontally. Neither does flip_h on the Sprite node. As far as I can see, you have to make a hurtbox for the left and right facing attacks, running a check to see of the Animated Sprite is flipped and enabling the corresponding hurtbox . Everything else is spot on, just baffled but taking this hacky shortcut that no longer works in Godot 3.1.
This demo was made in Godot 3.1. Scaling any Node2D will also affect its children.
@@Kidscancode Whoops, I used a Node instead of a Node 2D and didn't realize that Nodes don't have transform information, but Node 2Ds do. I think that should be mentioned in this video.
very helpfull, thanks
can we use the same technique with AnimatedSprite?
AnimatedSprite can't enable/disable the collision shape.
@@Kidscancode thank you for the quick reply. I'll try with AnimationPlayer
Great!
Similar thing can be done without animationplayer. You just need timer to set for how long area2d should be active :)
Emaleth very true, however the animation player adds the convenience of seeing exactly when something will occur in an animation and being able to easily edit it for new animations aswell. I used to use the timer method myself and I hate myself for it now because this is so much easier XD
@@minebrostj1430 yes, but if you like me have already player done and then you want to add melee, well... for me at least, as a beginner, it was simpler.
@@emaleth6518 yeah I agree, that's why I used timers in the first place, I'm working on transferring it all to the animation player now.
I might be making myself look stupid but uhhh......... how did you make the hurtbox?
It's an Area2D.
@@Kidscancode Is hurtbox the name?
Yes.
wow i wonder why you didnt get million sub
Maybe I missed something but did you have a script in the area2D or something? It's not exactly working.
Yes, you can see it in the written version: kidscancode.org/godot_recipes/3.x/animation/melee_attacks/
@@Kidscancode I solved my problem; getting variables from the said area 2D since the damage dealing function is interacting with the area 2D; I found a way to pass the info to the main body of the player.
Umm... WTF is group?
I think it's a category of objects that can be hurt (enemies) or destroyed (barrels, treasure chests).
In godot 4 please :D
I don't know how you did it. There was no collision trigger on my version (3.1.1), so I submitted a bug.
If you can provide a Godot project demo, I'll see if I missed anything.
github.com/godotengine/godot/issues/28803
спс
Awesome video! Best explanation possible for a real time game ;) Keep it up #VaiBrasil
Can you make a gun tutorial? Something like enter the gungeon, but with Godot. There are no good tutorials on guns, would love it if you made one!
There are lots of good tutorials on creating different kinds of projectiles. See the official godot-demos, GDQuest, GameEndeavor, etc.
Hmmm