One small detail: For people having problems flipping their collisions to the left side, you can try using: if Input.is_action_pressed("right"): get_node("AttackArea").set_scale(Vector2(1, 1)) elif Input.is_action_pressed("left"): get_node("AttackArea").set_scale(Vector2(-1, 1)) Hope it helps, sorry for the trouble!
this doesnt work? i put in my code and activated collision view but the attack area stays on the right edit: it only kind of works for me. it doesnt flip when i turn around but rather when i attack and then move. so if i want the collision to flip, i have to be holding the right or left key before the attack animation finishes. edit 2: i finally got it to work! i had it under my animation finished function so it did not work properly. thank you!
Hi, when I put this in my script it did flip the collision to the left side but it pushes the left side collision too far away in the x axis from the player meaning there is a large space between the player sprite and the collision. Any help would be much appreciated :)
I've been looking for this for HOURS! Nobody else could explain to me how to do it, and finally you did. Thank you! Now my frog can croak without messing the animations.
pal, i was about to give just up because i couldnt figure out how to make a animation finish without keeping the input just pressed. the answers i found where gross you just saved the day. thank you alot i wish you the best bro
hi there .I realise you haven't made any videos for over a year. but i just want to say how much I appreciate your videos and that without them i could never have progressed with my own game this far. i hope one day you will return to make more content but i realise everyone is busy these days. i wish you the best and hope you return . thank you so much for your videos!
I think the animation player is very complicated, and also, i wasn't wanting to redo everything i had done, so thank you so much for this tutorial, I'll try it as soon as possible
I just learned how to do the grid function on GIMP and it makes things way easier. If youset the grid to 16 x 16 then use a 32 x 32 (or similar dimension) you have a cross down the middle so you can line the sprites up.
Because i didn't know how to turn the Area2D in the other direction, i created a copy of the area on the other side of my sprite, and added the same code using the name of the copy(CollisionShape2D and CollisionShape2D2), it worked 😅
I feel like I have WAY more control over what is actually happening with Animated Sprite. Sure the animation player can do a lot more. It can alter pretty much any number from a node. Problem is if something breaks with that I will have NO IDEA what broke or how to fix it. With the Animated sprite I can just bypass using the .play() function entirely if I want too. Because I can tell Godot what frame and animation to play. Its awesome.
Stumbled on this great tutorial while trying to fix my situation. Maybe you can help me out? Idle and moving right is perfectly fine but the collision 2d on my sprite don't stay on the sprite once I move left? The shape moves out further left... Not the area attack but my actual sprite hit box
This tutorial is amazing! I want to add an attack 2, attack3 . All separate keys but I've already used the animation finished and signals how would I go about adding more attacks to this script? I've tried doing this tutorial multiple times for each attack but I can't get it to work. Cud u do a further tutorial for this? Thanks
HELLO: 3, how could I do what you do but with another movement system than yours: c I don't know what to do mine is like this func _physics_process (delta): control S () movement() spritedirection_loop () damage_loop () if moverirection! = Vector2 (0,0): anim_switch ("walk") plus: anim_switch ("inactive") function controls (): LEFT var = Input.is_action_pressed ("ui_left") RIGHT var = Input.is_action_pressed ("ui_right") var UP = Input.is_action_pressed ("ui_up") var DOWN = Input.is_action_pressed ("ui_down") movedirection.x = -int (LEFT) + int (RIGHT) movedirection.y = -int (UP) + int (DOWN) Should I erase everything and do it like you do? the truth if I delete mine tends to do many things that are outside the attacks Help please I'm stuck here
Hello, dear Dev! Your tutorial is brilliant, and I have one question! So, when I press jump and after the press enter, what is my attack button, my little hero starts to play the fall animation when he's on the ground. After I press enter again, it jump to the idle animation, so this is a really little bug, but it's here. :))) What can I do against that?
Very great video!! It helped me a lot but there are two main Problems I have. I can't flip the side of the collision shape (even not with the tips in the comments or with the command "$Attackarea/collisionshape2d.flip_h = true/false") I'm also havin issues with attacking while jumping. in that case my layer gets stuck in jumping animation and I have to click attack to walk again. I would be very happy if you could make a second part of this video where you explain how to improve the script with jumping and change attack side.
If you have attack animations for each direction, add a key to the first frame of the transform rotation value of the collission shape based on which direction you're facing. So that when that animation plays it'll rotate the shape accordingly.
Thank you! Haha, yeah, tell me about it. When I used to search through Godot tutorials all of them used AnimationPlayer too, so I wanted to give a bit of aid to the ones who used AnimatedSprite like I do :D
Thank you for the tutorial! Is there a way to make dynamic collision for attacks? Like it was in Weaponlord: sword is moving during animation => collision rect changes for every frame.
Great Tutorial. But I'm facing a problem now, the player character is passing through the enemy and their Collison is not being detected, only the attack in the sword area. Any idea about this ?
Hi, great video! I'm trying to do a fighting game so I need to use the hitbox on an exact frame. I need the hitbox to show only on frame 2 of an attack, for example. Can you help me, please? Thank you!
Oh yes, my next tutorial will be about that! You need to use a function called "match" and the signal, "frame_changed()" in AnimatedSprite and apply them to your code :D
@@antidevgodot Thank you so much for the quick response =). I spent my day trying to do this and failing. Even tried using the animation player, but I don't have spritesheets to work! I will wait your next video to continue this part. For now, I will focus on something else. Thank you again!
I was having a problem where I would push the button and the first frame of my attack animation would play before my character locked up. Some testing saw that isAttacking was returning 'true', so the input was being received properly. Here's how I solved it: func get_input(): movement = Vector2() if Input.is_action_pressed("left") and isAttacking == false: movement.x = -speed $Sprite.play("walk") elif Input.is_action_pressed("right") and isAttacking == false: movement.x = speed $Sprite.play("walk") else: if isAttacking == true: pass else: movement.x = 0 $Sprite.play("idle") This is my movement code. If left or right are pressed, walking animations are played (making a fighting game so don't need to flip sprites yet). The change I made was on what happens otherwise. I added an additional conditional that checks if isAttacking is returning true, and passes if it is. Otherwise, it plays "idle". This extra level of prevention for the return to the idle animation was enough to solve the problem. The comments on this question paired well with AntiDev's advice in helping solve the problem: godotengine.org/qa/53696/the-attack-animation-doesnt-finish-help-me
Hey! Are you sure that there isn't any animation "overwriting" the other? It's common for two animations to play at the same time by mistake, resulting in one of the two not playing.
Pikku Cocoa if you have a line of code that says: "$AnimatedSprite.flip_h = true" when the character moves left, do the same with the Area2D that holds the collision for the sword. :)
@@antidevgodot Thanks for the answer! Your videos are really helpful :D But it gives me the error: Invalid set index 'flip_h' (on base: 'Area2D') with value of type 'bool'.
@@anamendez1970 Hello again! You were right. It indeed gives an error back. Try something like: if Input.is_action_pressed("right"): get_node("AttackArea").set_scale(Vector2(1, 1)) elif Input.is_action_pressed("left"): get_node("AttackArea").set_scale(Vector2(-1, 1)) Hope it helps!
kinda wish i found this a little earlier 😅i have the longest setup for animations, since i had issue with the attack and idle animation being called at the same time and with the same if statements, countering eachother. gonna try this one next time, looks, a lot more simple and easy on the eyes when looking through the script
This was great, and I spent like 10mins trying to figure out why mine errored every time, until I realised get_node is case sensitive, DOH! My Question however, how to I get the Attack Area to enable at a certain sprite frame ?
If anyone wants too to attack while running just type "if isAttacking == false:" before playing the run animation. like so if isAttacking == false: $AnimatedSprite.flip_h = true $AnimatedSprite.play("Run")
Thanks a lot! And that's a good question. Personally I've never used KinematicBody2D for an enemy, but you could try using the signal "on_body_entered() instead of "on_Area_entered()" that could help.
@@antidevgodot I don't know why but I don't have this node. So, I added an area2D as a child of the kinematicBody and a collisionShape2D as a child of the area and the collision is a copy of the collision of the kinematicBody. It seems to work. Thanks for your answer
Alexandra Pietri ah! That actually makes a lot of sense. I always tend to forget that you can use both! I'm happy that it worked, and good luck with your project!
Hello devs! :D Well, I tried to solve this problem, but when I create an area 2d like a child of KinematicBody2D, it has problem with my character move's code. But when I don't use Area2D, there's no problem. How can my enemy move when it's Area2D? I can kill enemy, but it can't walk, and that's unfair. :D
Please help. What method would you use to flip_h the AttackArea(area2d) when the parent flip_h. Otherwise, when my sprite turns to face the opposite direction, the area2d collision is behind it. It seems the area2d does not have a flip_h, so how would you fix this?
I hope your channel grows alottttttt ilyyyy More tutorials pls Can you make tutorials on enemy ai and boss levels Like If I enter the boss stage Entrance and exit closes it shouldn't open till I beat the boss plssssss
hello i am having a problem when i press x it dosent show the animation and i even assinged the attack to x can u plz give me the code thank u and can u give the mega man assets plzzz
if Input.is_action_just_pressed("attack"): $AnimationPlayer.play("Attack") isAttacking = true
if is_on_floor(): if Input.is_action_just_pressed("jump"): motion.y -= JUMPSPEED if Input.is_action_just_pressed("attack"): $AnimationPlayer.play("Attack")
if !is_on_floor(): if motion.y < 0: $AnimationPlayer.play("Jump") elif motion.y > 0: $AnimationPlayer.play("Fall") motion = move_and_slide(motion, UP) func _on_AnimationPlayer_animation_finished(anim_name): if $AnimationPlayer.current_animation == "Attack": isAttacking = false THIS IS MY CODE
I have a problem, when my character turns to the left, his position changes and moves away from the Collisionshape a bit, the same happens with the attack animation, can someone help me?
== is always needed in "if" statements. "=" and "==" don't mean the same in programming. = is "Program, make this equal to this" == is "Program, if this is equal to this..." I hope I've explained it well. "==" is always used in conditions. Not only in GDscript, but in every (modern) language, I think.
Hello, I'm having issues with my AnimatedSprite, animation is working fine but once testing and I press the assigned key (in this example Attack) It plays the animation REALLY quickly and it happens in a blink of an eye. I was wondering if there is a way to slow this down at all? Code below; #Attack Animation section# if Input.is_action_just_pressed("Attack"): (This is the S key) $AnimatedSprite.play("Attack2"); isAttacking == true; velocity = move_and_slide(velocity, FLOOR) Thanks!
I was also curious if you touch on how to setup a key to perform an animation whilst a key is being held down? Example would be holding down Tab to crouch but then the crouch animation just continuously play whilst Tab is being held down (unless moving either way)
The animation playing quickly could be caused by various reasons. Check the AnimatedSprite frame speed or that an animation is not "overwriting" another one. :) Sorry for taking too long to reply!
Please make a tutorial on Enemy's with health using this same hitbox system, I've tried making one myself but it would not work, also nobody has a good tutorial on it, thanks!
I need help, the animation after writing the code and testing it, when I type the attack key instead of stopping it continues, and I no longer have it pressed, what do I do?
I have a problem, when I press the key to attack, it only makes the animation of one frame and it is very fast, I already checked the speed of the animation in the code but I can't find the solution.
So I ran into a problem with this: Basically, I had to explicitly set the attack area's collision shape to be enabled ($attackarea/CollisionShape2d.disabled = false) in the if statement for when the attack button is pressed in order to get it to work. It would stay enabled if I didn't do that. Other than that, there were a few bumps in the road I ran into, but I managed to fix it before I wrote this comment. It was really messing with my head that I couldn't get the attack animation to play entirely, but then I realized I forgot the if statement. I also couldn't get the signal for an area entering the enemy to work until I realized my collision layers/masks weren't set properly (I had them set differently from the default because I had some code already in my particular enemy to make it also "die" when you jump on its head) I'm mentioning this here in case anyone else runs into the same problems I did. Everything else about this tutorial is spot on!
hm, this doesn't seem to be a good solution since your area is open as long the animation is playing, which means another object can get hit multiple times.
Hi can you make tutorial about enemy following player, attacking player, and make the player die if you make this, this would be soo much helpful!! i like your video btw
One small detail:
For people having problems flipping their collisions to the left side, you can try using:
if Input.is_action_pressed("right"):
get_node("AttackArea").set_scale(Vector2(1, 1))
elif Input.is_action_pressed("left"):
get_node("AttackArea").set_scale(Vector2(-1, 1))
Hope it helps, sorry for the trouble!
thanks, + 1 subscribe
this doesnt work? i put in my code and activated collision view but the attack area stays on the right
edit: it only kind of works for me. it doesnt flip when i turn around but rather when i attack and then move. so if i want the collision to flip, i have to be holding the right or left key before the attack animation finishes.
edit 2: i finally got it to work! i had it under my animation finished function so it did not work properly. thank you!
alliumCepa Glad it worked!
I wanna add jump attack
Help 😔
Hi, when I put this in my script it did flip the collision to the left side but it pushes the left side collision too far away in the x axis from the player meaning there is a large space between the player sprite and the collision. Any help would be much appreciated :)
I finally found a person who teaches well. Thank you very much, helped me a lot
Everton Cardoso I really really really appreciate your kind words! Stay tuned for more! :DD thanks a lot for passing by!
I've been looking for this for HOURS! Nobody else could explain to me how to do it, and finally you did. Thank you! Now my frog can croak without messing the animations.
Hey could you help my character geta stuck and i did the same thing as mentioned in the video but doesnt work
@@CallMeDrumz I no longer have any idea what this was even about, let alone how to help you with zero details. Asking on Reddit may help you more
Nothing like being stuck on a problem for three days only to realize the solution was a single if statement. Thank you so much this helped immensely.
This is perfect. I was wanting to do something simpler not needing the animation player...and this is the type of solution I had in mind!
Your enemy attack tutorial is very perfect, I was looking for it a lot and I couldn't find it, thanks! greetings from Argentina 🇦🇷🇦🇷
pal, i was about to give just up because i couldnt figure out how to make a animation finish without keeping the input just pressed. the answers i found where gross you just saved the day. thank you alot i wish you the best bro
I almost never leave comments, but just wanted to stop and say, you are amazing at teaching, you solved my problem. Thanks a lot.
Thank you so much!!! I really appreciate it!
Good luck in your Godot path!!
Thank you for this tutorial your teaching is so clear! Helped me figure out why my animation wouldn’t play correctly
true
This is is basically what I used to do back in Unity and it's almost the same in Godot which is a good thing.
hi there .I realise you haven't made any videos for over a year. but i just want to say how much I appreciate your videos and that without them i could never have progressed with my own game this far. i hope one day you will return to make more content but i realise everyone is busy these days. i wish you the best and hope you return . thank you so much for your videos!
I think the animation player is very complicated, and also, i wasn't wanting to redo everything i had done, so thank you so much for this tutorial, I'll try it as soon as possible
I just learned how to do the grid function on GIMP and it makes things way easier. If youset the grid to 16 x 16 then use a 32 x 32 (or similar dimension) you have a cross down the middle so you can line the sprites up.
Because i didn't know how to turn the Area2D in the other direction, i created a copy of the area on the other side of my sprite, and added the same code using the name of the copy(CollisionShape2D and CollisionShape2D2), it worked 😅
Thank you for this tutorial, I have been messing 3 days with the animation not playing correctly. Thanks to you I have finally fixed it.
I'm glad you could fix it and that I could help!!
thanks bro I was looking for this a long time THANK YOU
Ikiri Glad I could help! :DDD
I work on my game project in godot and .... You are my saviour I really appreciate you .... all my greatings to you from egypt
Thanks for the kinds comments my man :) good luck with your Godot projects, greetings from Germany!
I search for revolving my trouble with animation for days !! you save me thanks ! great viedo
I feel like I have WAY more control over what is actually happening with Animated Sprite.
Sure the animation player can do a lot more. It can alter pretty much any number from a node. Problem is if something breaks with that I will have NO IDEA what broke or how to fix it. With the Animated sprite I can just bypass using the .play() function entirely if I want too. Because I can tell Godot what frame and animation to play. Its awesome.
Awesome tutorial, you are a great teacher :) you deserve WAY more then 500 subs, but I am one of those subs! 👍
The Devine Thank you so much!!! I really appreciate it. I'm glad I helped. :)
Ahh!! Didn't see the rest of your comment, thank you so much for subscribing and for your kind words! :DD
Stumbled on this great tutorial while trying to fix my situation.
Maybe you can help me out?
Idle and moving right is perfectly fine but
the collision 2d on my sprite don't stay on the sprite once I move left?
The shape moves out further left...
Not the area attack but my actual sprite hit box
You can skip the intro at 1:00 :)
best one who explained attacks in godot thanks
This tutorial is amazing! I want to add an attack 2, attack3 . All separate keys but I've already used the animation finished and signals how would I go about adding more attacks to this script? I've tried doing this tutorial multiple times for each attack but I can't get it to work. Cud u do a further tutorial for this? Thanks
you saved my life... i was thinking of leaving the idea of making my own game because of this..thank you sooo much
Glad I could help! :D
this doesn't seem to work well with the Combo system if using an state machine
only the first hit works, I have no idea how make each hit count
HELLO: 3, how could I do what you do but with another movement system than yours: c I don't know what to do mine is like this
func _physics_process (delta):
control S ()
movement()
spritedirection_loop ()
damage_loop ()
if moverirection! = Vector2 (0,0):
anim_switch ("walk")
plus:
anim_switch ("inactive")
function controls ():
LEFT var = Input.is_action_pressed ("ui_left")
RIGHT var = Input.is_action_pressed ("ui_right")
var UP = Input.is_action_pressed ("ui_up")
var DOWN = Input.is_action_pressed ("ui_down")
movedirection.x = -int (LEFT) + int (RIGHT)
movedirection.y = -int (UP) + int (DOWN)
Should I erase everything and do it like you do? the truth if I delete mine tends to do many things that are outside the attacks
Help please I'm stuck here
It helped a lot thanks and God bless you,it was really amazing and simple but you kinda took a long time to explain 😄 anyway thanks again
Hello, dear Dev!
Your tutorial is brilliant, and I have one question!
So, when I press jump and after the press enter, what is my attack button, my little hero starts to play the fall animation when he's on the ground. After I press enter again, it jump to the idle animation, so this is a really little bug, but it's here. :))) What can I do against that?
same error. did you solve it?
same error me 2 did u solve it. :(
Guys, try state machines.
It solved alot.
Very great video!! It helped me a lot but there are two main Problems I have. I can't flip the side of the collision shape (even not with the tips in the comments or with the command "$Attackarea/collisionshape2d.flip_h = true/false") I'm also havin issues with attacking while jumping. in that case my layer gets stuck in jumping animation and I have to click attack to walk again.
I would be very happy if you could make a second part of this video where you explain how to improve the script with jumping and change attack side.
This is a very very good tutorial! Thank you so much! Please upload more videos 😁👍
Ervin Farhan I really appreciate it!! I will, I promise! :D
How set-up collisionshape2d in 4 direction?
If you have attack animations for each direction, add a key to the first frame of the transform rotation value of the collission shape based on which direction you're facing. So that when that animation plays it'll rotate the shape accordingly.
Great Godot content. Helped me so much thanks :)
thanks buddy it was very simple to follow and very clear :)
Thank you so much! I hope it helped!
dude i love you so much, ive been stuck on this stupid thing for like 10 hours, i can't thank you enough
I'm glad your problem was solved! Good luck with your game :D
very good video man, I'm glad you use animatedsprite because most things are just animation player and I think it's kinda a time waste
Thank you! Haha, yeah, tell me about it. When I used to search through Godot tutorials all of them used AnimationPlayer too, so I wanted to give a bit of aid to the ones who used AnimatedSprite like I do :D
Thank you for the tutorial! Is there a way to make dynamic collision for attacks? Like it was in Weaponlord: sword is moving during animation => collision rect changes for every frame.
Yes you can do that with the animation player, you just need to key the position of the collision shape for that :)
ok....very nice and so on lol.....but how do you attack while running ?
Terimakasih teman ini sangat membantu saya. ilmu yang anda bagikan pasti bisa membantu saya menjadi seorang game developer individual
Very well explained video, thank you!
This is a great video! Can you do a video if where you were top rpg with all 8 directions?
Thank you very much! I was losing my mind, trying to figure out how to do this
What if I want to activate the collison later? is it possible? for my attacking animation I need to activate it on the 5th frame.
Great Tutorial. But I'm facing a problem now, the player character is passing through the enemy and their Collison is not being detected, only the attack in the sword area. Any idea about this ?
it's been a year but check your layers and make sure that the player is different from world / enemy
Nice tutorial
Thanks!
Hi, great video! I'm trying to do a fighting game so I need to use the hitbox on an exact frame. I need the hitbox to show only on frame 2 of an attack, for example. Can you help me, please? Thank you!
Oh yes, my next tutorial will be about that! You need to use a function called "match" and the signal, "frame_changed()" in AnimatedSprite and apply them to your code :D
@@antidevgodot Thank you so much for the quick response =). I spent my day trying to do this and failing. Even tried using the animation player, but I don't have spritesheets to work!
I will wait your next video to continue this part. For now, I will focus on something else.
Thank you again!
Kaio Tavares No need to thank me! Expect it very soon!🥳🥳
When i pressed the attack and the jump button in the same time, it stucks on the jump animation
Uhh how to fix it? Thanks
you must put if Input.is_action_pressed("ui_up")&& is_atack == false:
@@gonzitarod2885 ohh thanks!
hi same thing happened to me but GonzitaRod's solution doesnt work for me
Awesome tutorial!
thank you so much! :D
I was having a problem where I would push the button and the first frame of my attack animation would play before my character locked up. Some testing saw that isAttacking was returning 'true', so the input was being received properly. Here's how I solved it:
func get_input():
movement = Vector2()
if Input.is_action_pressed("left") and isAttacking == false:
movement.x = -speed
$Sprite.play("walk")
elif Input.is_action_pressed("right") and isAttacking == false:
movement.x = speed
$Sprite.play("walk")
else:
if isAttacking == true:
pass
else:
movement.x = 0
$Sprite.play("idle")
This is my movement code. If left or right are pressed, walking animations are played (making a fighting game so don't need to flip sprites yet). The change I made was on what happens otherwise. I added an additional conditional that checks if isAttacking is returning true, and passes if it is. Otherwise, it plays "idle". This extra level of prevention for the return to the idle animation was enough to solve the problem.
The comments on this question paired well with AntiDev's advice in helping solve the problem:
godotengine.org/qa/53696/the-attack-animation-doesnt-finish-help-me
Hey! Are you sure that there isn't any animation "overwriting" the other? It's common for two animations to play at the same time by mistake, resulting in one of the two not playing.
@@antidevgodot Thanks for the prompt reply on a week old video, means a lot.
Solved it, edited original response for visibility.
Thanks
Hi! How do I make it so when the character is turned to the left, the collision box changes it's position?
Pikku Cocoa if you have a line of code that says: "$AnimatedSprite.flip_h = true" when the character moves left, do the same with the Area2D that holds the collision for the sword. :)
@@antidevgodot Thanks for the answer! Your videos are really helpful :D
But it gives me the error: Invalid set index 'flip_h' (on base: 'Area2D') with value of type 'bool'.
Pikku Cocoa Thanks for the feedback! And give me a sec, I'll go into my own project to check out a solution.
@@anamendez1970 Hello again! You were right. It indeed gives an error back. Try something like:
if Input.is_action_pressed("right"):
get_node("AttackArea").set_scale(Vector2(1, 1))
elif Input.is_action_pressed("left"):
get_node("AttackArea").set_scale(Vector2(-1, 1))
Hope it helps!
@@antidevgodot It worked, thank you so much!
Dope video hommie
kinda wish i found this a little earlier 😅i have the longest setup for animations, since i had issue with the attack and idle animation being called at the same time and with the same if statements, countering eachother.
gonna try this one next time, looks, a lot more simple and easy on the eyes when looking through the script
nevermind, switched to this method now, it's way easier to handle without a statemachine setup
how to talk and attack in same time? is that doable with animated sprite node?
What megaman series is that you using one of the Weil guardian ?
Thanks I was stuck in this part. Great tutorial
Mark Anthony Fordan I'm glad it helped, thanks for watching!! :D
This was great, and I spent like 10mins trying to figure out why mine errored every time, until I realised get_node is case sensitive, DOH! My Question however, how to I get the Attack Area to enable at a certain sprite frame ?
Never mind, Google is my Friend; I added frame_changed signal, and in the function had is isAttack and Frame == x then enable AttackArea.
Thank you !! Great tut !!!
Thank you for your words!! :D
the movement= move_and_slide line is showing error that only 0 arguments are allowed but recieved 2
If you use Godot 4 Just write "move_and_slide()"
If anyone wants too to attack while running just type "if isAttacking == false:" before playing the run animation. like so
if isAttacking == false:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Run")
Thanks for your tutorials is very very good and helpful but my enemy is a kenematicBody2D so how I can do the same but with this type of element ?
Thanks a lot! And that's a good question. Personally I've never used KinematicBody2D for an enemy, but you could try using the signal "on_body_entered() instead of "on_Area_entered()" that could help.
@@antidevgodot I don't know why but I don't have this node. So, I added an area2D as a child of the kinematicBody and a collisionShape2D as a child of the area and the collision is a copy of the collision of the kinematicBody. It seems to work. Thanks for your answer
Alexandra Pietri ah! That actually makes a lot of sense. I always tend to forget that you can use both!
I'm happy that it worked, and good luck with your project!
Hello devs! :D
Well, I tried to solve this problem, but when I create an area 2d like a child of KinematicBody2D, it has problem with my character move's code. But when I don't use Area2D, there's no problem. How can my enemy move when it's Area2D? I can kill enemy, but it can't walk, and that's unfair. :D
hey i know its been 4 years but why is godot telling me there are too many arguments after move_and_slide?
how do you make it face the other way
the attackarea collisionshape
Thx for this simple good video 🙏
Oh I had no idea I was steam friends with a somewhat-popular youtuber. Sweet!
Please help. What method would you use to flip_h the AttackArea(area2d) when the parent flip_h. Otherwise, when my sprite turns to face the opposite direction, the area2d collision is behind it. It seems the area2d does not have a flip_h, so how would you fix this?
How can I do that if my animated_sprite of the player is flip_h, the globalposition of the area = the left player?
thank you a lot, very simple and to the point!!
Thanks!!!
thank you jeebus
You're amazing. helped me a lot thanks!!
Demioni Thank you so much for the kind words!!!
I'm glad I helped :D
what condition should i put to flip animation of attack acc to direction in which player is facing ?
How do I make it also attack the left activating a collision on the left and without activating the right?
Amigo amo este video, mil gracias, me has ayudado mucho ☺️☺️☺️☺️☺️
I hope your channel grows alottttttt ilyyyy
More tutorials pls
Can you make tutorials on enemy ai and boss levels
Like
If I enter the boss stage
Entrance and exit closes it shouldn't open till I beat the boss plssssss
hello i am having a problem when i press x it dosent show the animation and i even assinged the attack to x can u plz give me the code thank u and can u give the mega man assets plzzz
my player freezes when attack anim is finished.. signals not working
extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 12
const MAXFALLSPEED = 200
const MAXSPEED = 100
const ACCEL = 10
const JUMPSPEED = 200
var motion = Vector2()
var facing_right = true
var isAttacking = false
func _ready():
pass
func _physics_process(delta):
motion.y += GRAVITY
if motion.y > MAXFALLSPEED:
motion.y = MAXFALLSPEED
if facing_right == true:
$Sprite.scale.x = 1
else:
$Sprite.scale.x = -1
motion.x = clamp(motion.x,-MAXSPEED,MAXSPEED)
if Input.is_action_pressed("right") && isAttacking == false:
motion.x += ACCEL
facing_right = true
$AnimationPlayer.play("Run")
elif Input.is_action_pressed("left") && isAttacking == false:
motion.x -= ACCEL
facing_right = false
$AnimationPlayer.play("Run")
else:
motion.x = lerp(motion.x,0,0.2)
if isAttacking == false:
$AnimationPlayer.play("Idle")
if Input.is_action_just_pressed("attack"):
$AnimationPlayer.play("Attack")
isAttacking = true
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y -= JUMPSPEED
if Input.is_action_just_pressed("attack"):
$AnimationPlayer.play("Attack")
if !is_on_floor():
if motion.y < 0:
$AnimationPlayer.play("Jump")
elif motion.y > 0:
$AnimationPlayer.play("Fall")
motion = move_and_slide(motion, UP)
func _on_AnimationPlayer_animation_finished(anim_name):
if $AnimationPlayer.current_animation == "Attack":
isAttacking = false
THIS IS MY CODE
I have a problem, when my character turns to the left, his position changes and moves away from the Collisionshape a bit, the same happens with the attack animation, can someone help me?
Very 👌
So I have a problem... I don't know if anyone has run into this but. When I try to set up the death animation it stops the enemy from dying.
Can i make the AttackArea change with every frame of the attack?
What is the difference between putting == instead of =???
== is always needed in "if" statements. "=" and "==" don't mean the same in programming.
= is "Program, make this equal to this"
== is "Program, if this is equal to this..."
I hope I've explained it well. "==" is always used in conditions. Not only in GDscript, but in every (modern) language, I think.
Thx 🙏 understood how to am gonna script my player in few minutes
Hello, I'm having issues with my AnimatedSprite, animation is working fine but once testing and I press the assigned key (in this example Attack) It plays the animation REALLY quickly and it happens in a blink of an eye. I was wondering if there is a way to slow this down at all?
Code below;
#Attack Animation section#
if Input.is_action_just_pressed("Attack"):
(This is the S key)
$AnimatedSprite.play("Attack2");
isAttacking == true;
velocity = move_and_slide(velocity, FLOOR)
Thanks!
I was also curious if you touch on how to setup a key to perform an animation whilst a key is being held down?
Example would be holding down Tab to crouch but then the crouch animation just continuously play whilst Tab is being held down (unless moving either way)
The animation playing quickly could be caused by various reasons. Check the AnimatedSprite frame speed or that an animation is not "overwriting" another one. :)
Sorry for taking too long to reply!
@@jellybeanconfirmed9049 And the crouching idea is a really good idea. Let me see if I can get into that after the next video I'm making. :)
Please make a tutorial on Enemy's with health using this same hitbox system, I've tried making one myself but it would not work, also nobody has a good tutorial on it, thanks!
Guess I could try :)
can you show us how you coded the jump slash?
what a life saver!
Что делать, если у врага тело не Area2d, а KineaticBody2d?
What should I do if the enemy's body is not Area2d, but KineaticBody2d?
hello i know this is old comment. Maybe you already found out but
You can still use a kinematicbody for enemy and add an area2D as it's child.
@@KoeK_oe Hi, yes, I have already solved this problem, but still thank you for your help
how do I make it so if my player hits again after he hit once it will change his hitting animation.
I need help, the animation after writing the code and testing it, when I type the attack key instead of stopping it continues, and I no longer have it pressed, what do I do?
its on loop
hi need help i cant see collision shape 2d in area 2d
I love your chanel, ths for help
I have a problem, when I press the key to attack, it only makes the animation of one frame and it is very fast, I already checked the speed of the animation in the code but I can't find the solution.
Add
if is_attacking == false
In the idle func
4:38
So I ran into a problem with this:
Basically, I had to explicitly set the attack area's collision shape to be enabled ($attackarea/CollisionShape2d.disabled = false) in the if statement for when the attack button is pressed in order to get it to work. It would stay enabled if I didn't do that.
Other than that, there were a few bumps in the road I ran into, but I managed to fix it before I wrote this comment. It was really messing with my head that I couldn't get the attack animation to play entirely, but then I realized I forgot the if statement. I also couldn't get the signal for an area entering the enemy to work until I realized my collision layers/masks weren't set properly (I had them set differently from the default because I had some code already in my particular enemy to make it also "die" when you jump on its head) I'm mentioning this here in case anyone else runs into the same problems I did.
Everything else about this tutorial is spot on!
Guys what if I using AnimationPlayer,6:31 what I will change in code animation ?
Thank You Sir ^_^
Thanks alot!!!
Thanks man
when you go to the left, how do you make the collision also turn to the left ?
Create a second collision box and make the other one disabled when you turn to left/right
@@mrtz187 make the collision animatedsprite's children and flip animatedsprite using scale.x instead of using flip_h
Thank you, great tutorial :) that what I was thinking about, how to use animated sprite with mlea attack :)
Hola! Como puedo contactar contigo? Un saludo
Antidevgodot@gmail.com
hm, this doesn't seem to be a good solution since your area is open as long the animation is playing, which means another object can get hit multiple times.
Hi can you make tutorial about enemy following player, attacking player, and make the player die if you make this, this would be soo much helpful!! i like your video btw
YES THAT WOULD BE AMAZING
Thanks for liking it! I guess I could work on that. :)
@@antidevgodot YESSSS THANK YOUU SOO MUCHH