Tutorial: How to create melee attacks using AnimatedSprite! (Godot Engine 3.2)

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 247

  • @antidevgodot
    @antidevgodot  4 роки тому +86

    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!

    • @itachiuzumaki5553
      @itachiuzumaki5553 4 роки тому +1

      thanks, + 1 subscribe

    • @alliumcepa857
      @alliumcepa857 4 роки тому +3

      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!

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      alliumCepa Glad it worked!

    • @evohollywood303
      @evohollywood303 3 роки тому

      I wanna add jump attack
      Help 😔

    • @benperrin1612
      @benperrin1612 3 роки тому

      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 :)

  • @evertoncardoso7471
    @evertoncardoso7471 4 роки тому +29

    I finally found a person who teaches well. Thank you very much, helped me a lot

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      Everton Cardoso I really really really appreciate your kind words! Stay tuned for more! :DD thanks a lot for passing by!

  • @aque9608
    @aque9608 8 місяців тому +2

    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.

    • @CallMeDrumz
      @CallMeDrumz 3 місяці тому

      Hey could you help my character geta stuck and i did the same thing as mentioned in the video but doesnt work

    • @aque9608
      @aque9608 3 місяці тому

      @@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

  • @ianmckenzie6715
    @ianmckenzie6715 Місяць тому

    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.

  • @scottpetrovic
    @scottpetrovic 3 роки тому +3

    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!

  • @JavierJaramillo-v6p
    @JavierJaramillo-v6p Рік тому +1

    Your enemy attack tutorial is very perfect, I was looking for it a lot and I couldn't find it, thanks! greetings from Argentina 🇦🇷🇦🇷

  • @actionninja6389
    @actionninja6389 3 роки тому

    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

  • @2xtreme-v8j
    @2xtreme-v8j 4 роки тому +1

    I almost never leave comments, but just wanted to stop and say, you are amazing at teaching, you solved my problem. Thanks a lot.

    • @antidevgodot
      @antidevgodot  4 роки тому

      Thank you so much!!! I really appreciate it!
      Good luck in your Godot path!!

  • @benperrin1612
    @benperrin1612 3 роки тому +3

    Thank you for this tutorial your teaching is so clear! Helped me figure out why my animation wouldn’t play correctly

  • @AxZelAnimations30
    @AxZelAnimations30 Рік тому

    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.

  • @Christopher-ty2gc
    @Christopher-ty2gc 2 роки тому +1

    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!

  • @fabricioaf89
    @fabricioaf89 Рік тому

    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

    • @princessbitch96
      @princessbitch96 7 місяців тому

      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.

  • @fabricioaf89
    @fabricioaf89 Рік тому +1

    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 😅

  • @vipervlame
    @vipervlame 4 роки тому

    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.

    • @antidevgodot
      @antidevgodot  4 роки тому

      I'm glad you could fix it and that I could help!!

  • @ikiri2735
    @ikiri2735 4 роки тому +3

    thanks bro I was looking for this a long time THANK YOU

  • @EtchGamer
    @EtchGamer 3 роки тому

    I work on my game project in godot and .... You are my saviour I really appreciate you .... all my greatings to you from egypt

    • @antidevgodot
      @antidevgodot  3 роки тому

      Thanks for the kinds comments my man :) good luck with your Godot projects, greetings from Germany!

  • @pipinpierard
    @pipinpierard 2 роки тому

    I search for revolving my trouble with animation for days !! you save me thanks ! great viedo

  • @VaSoapman
    @VaSoapman 3 роки тому +1

    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.

  • @thedevine3756
    @thedevine3756 4 роки тому

    Awesome tutorial, you are a great teacher :) you deserve WAY more then 500 subs, but I am one of those subs! 👍

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      The Devine Thank you so much!!! I really appreciate it. I'm glad I helped. :)

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      Ahh!! Didn't see the rest of your comment, thank you so much for subscribing and for your kind words! :DD

  • @optimusrandis654
    @optimusrandis654 3 місяці тому

    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

  • @antidevgodot
    @antidevgodot  4 роки тому +6

    You can skip the intro at 1:00 :)

  • @saeedsalem8535
    @saeedsalem8535 4 роки тому

    best one who explained attacks in godot thanks

  • @sonikrocket7881
    @sonikrocket7881 2 роки тому +2

    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

  • @kikosa1349
    @kikosa1349 4 роки тому

    you saved my life... i was thinking of leaving the idea of making my own game because of this..thank you sooo much

  • @Sr.Haruno
    @Sr.Haruno Рік тому +1

    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

  • @xxmundoetcxxetc5185
    @xxmundoetcxxetc5185 4 роки тому +2

    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

  • @zackcool6080
    @zackcool6080 2 роки тому

    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

  • @razsiadam2454
    @razsiadam2454 3 роки тому +1

    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?

  • @urbansongbirds8386
    @urbansongbirds8386 4 роки тому +1

    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.

  • @ervinfarhan9549
    @ervinfarhan9549 4 роки тому +1

    This is a very very good tutorial! Thank you so much! Please upload more videos 😁👍

    • @antidevgodot
      @antidevgodot  4 роки тому

      Ervin Farhan I really appreciate it!! I will, I promise! :D

  • @gabrielebianca1268
    @gabrielebianca1268 4 роки тому +5

    How set-up collisionshape2d in 4 direction?

    • @sechmascm
      @sechmascm 3 роки тому +2

      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.

  • @New_Gaming_Chair
    @New_Gaming_Chair 3 роки тому

    Great Godot content. Helped me so much thanks :)

  • @MegaAbhirox
    @MegaAbhirox 4 роки тому +1

    thanks buddy it was very simple to follow and very clear :)

    • @antidevgodot
      @antidevgodot  4 роки тому

      Thank you so much! I hope it helped!

  • @postano9153
    @postano9153 4 роки тому

    dude i love you so much, ive been stuck on this stupid thing for like 10 hours, i can't thank you enough

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      I'm glad your problem was solved! Good luck with your game :D

  • @brianwindson9656
    @brianwindson9656 4 роки тому

    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

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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

  • @colddeath9797
    @colddeath9797 3 роки тому +1

    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.

    • @jeanmakesgames
      @jeanmakesgames 2 роки тому

      Yes you can do that with the animation player, you just need to key the position of the collision shape for that :)

  • @I_Stern
    @I_Stern 2 роки тому

    ok....very nice and so on lol.....but how do you attack while running ?

  • @rizkymaulana1195
    @rizkymaulana1195 14 днів тому

    Terimakasih teman ini sangat membantu saya. ilmu yang anda bagikan pasti bisa membantu saya menjadi seorang game developer individual

  • @fireblo33om
    @fireblo33om 2 роки тому

    Very well explained video, thank you!

  • @carlostanner5453
    @carlostanner5453 3 роки тому

    This is a great video! Can you do a video if where you were top rpg with all 8 directions?

  • @iPePod
    @iPePod 3 роки тому

    Thank you very much! I was losing my mind, trying to figure out how to do this

  • @thelastronin7277
    @thelastronin7277 Рік тому

    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.

  • @kartikeysharma5304
    @kartikeysharma5304 3 роки тому +1

    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 ?

    • @asyria216
      @asyria216 Рік тому

      it's been a year but check your layers and make sure that the player is different from world / enemy

  • @KanishkaDilshan
    @KanishkaDilshan 4 роки тому +1

    Nice tutorial

  • @Migraman2
    @Migraman2 4 роки тому +1

    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!

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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

    • @Migraman2
      @Migraman2 4 роки тому

      @@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!

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      Kaio Tavares No need to thank me! Expect it very soon!🥳🥳

  • @darkconage2867
    @darkconage2867 4 роки тому +2

    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

    • @gonzitarod2885
      @gonzitarod2885 4 роки тому +1

      you must put if Input.is_action_pressed("ui_up")&& is_atack == false:

    • @darkconage2867
      @darkconage2867 4 роки тому +1

      @@gonzitarod2885 ohh thanks!

    • @ShineOrSomething
      @ShineOrSomething 3 роки тому

      hi same thing happened to me but GonzitaRod's solution doesnt work for me

  • @paologeovanny6176
    @paologeovanny6176 4 роки тому +1

    Awesome tutorial!

  • @zonkrt3463
    @zonkrt3463 4 роки тому +1

    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

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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.

    • @zonkrt3463
      @zonkrt3463 4 роки тому

      @@antidevgodot Thanks for the prompt reply on a week old video, means a lot.
      Solved it, edited original response for visibility.

    • @evohollywood303
      @evohollywood303 3 роки тому

      Thanks

  • @anamendez1970
    @anamendez1970 4 роки тому +2

    Hi! How do I make it so when the character is turned to the left, the collision box changes it's position?

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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. :)

    • @anamendez1970
      @anamendez1970 4 роки тому +1

      @@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'.

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      Pikku Cocoa Thanks for the feedback! And give me a sec, I'll go into my own project to check out a solution.

    • @antidevgodot
      @antidevgodot  4 роки тому +4

      @@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!

    • @anamendez1970
      @anamendez1970 4 роки тому

      @@antidevgodot It worked, thank you so much!

  • @lexflow2319
    @lexflow2319 3 роки тому

    Dope video hommie

  • @gargoyled_drake
    @gargoyled_drake 2 роки тому

    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

    • @gargoyled_drake
      @gargoyled_drake 2 роки тому

      nevermind, switched to this method now, it's way easier to handle without a statemachine setup

  • @Blue-Scorpion
    @Blue-Scorpion 2 роки тому

    how to talk and attack in same time? is that doable with animated sprite node?

  • @aerutus4720
    @aerutus4720 4 роки тому

    What megaman series is that you using one of the Weil guardian ?

  • @akosifords
    @akosifords 4 роки тому

    Thanks I was stuck in this part. Great tutorial

    • @antidevgodot
      @antidevgodot  4 роки тому

      Mark Anthony Fordan I'm glad it helped, thanks for watching!! :D

  • @TheRealKaiProton
    @TheRealKaiProton 4 роки тому

    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 ?

    • @TheRealKaiProton
      @TheRealKaiProton 4 роки тому

      Never mind, Google is my Friend; I added frame_changed signal, and in the function had is isAttack and Frame == x then enable AttackArea.

  • @znomad8026
    @znomad8026 4 роки тому +1

    Thank you !! Great tut !!!

  • @zazackstickman5983
    @zazackstickman5983 7 місяців тому

    the movement= move_and_slide line is showing error that only 0 arguments are allowed but recieved 2

    • @balaboss78
      @balaboss78 5 місяців тому

      If you use Godot 4 Just write "move_and_slide()"

  • @markflakezCG
    @markflakezCG 4 роки тому +1

    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")

  • @alexandraP7475
    @alexandraP7475 4 роки тому +1

    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 ?

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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.

    • @alexandraP7475
      @alexandraP7475 4 роки тому +1

      @@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

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      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!

    • @razsiadam2454
      @razsiadam2454 3 роки тому

      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

  • @george-philippmerchel9314
    @george-philippmerchel9314 29 днів тому

    hey i know its been 4 years but why is godot telling me there are too many arguments after move_and_slide?

  • @sully8495
    @sully8495 3 роки тому

    how do you make it face the other way
    the attackarea collisionshape

  • @adr1an29
    @adr1an29 3 роки тому

    Thx for this simple good video 🙏

  • @PrivateBooth
    @PrivateBooth 4 роки тому

    Oh I had no idea I was steam friends with a somewhat-popular youtuber. Sweet!

  • @DennisKwasnycia
    @DennisKwasnycia 4 роки тому

    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?

  • @gonzitarod2885
    @gonzitarod2885 4 роки тому

    How can I do that if my animated_sprite of the player is flip_h, the globalposition of the area = the left player?

  • @pranksies4496
    @pranksies4496 4 роки тому

    thank you a lot, very simple and to the point!!

  • @lemmmakestunes8312
    @lemmmakestunes8312 2 місяці тому

    thank you jeebus

  • @demioni1561
    @demioni1561 4 роки тому

    You're amazing. helped me a lot thanks!!

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      Demioni Thank you so much for the kind words!!!
      I'm glad I helped :D

  • @xerogaming2127
    @xerogaming2127 4 роки тому

    what condition should i put to flip animation of attack acc to direction in which player is facing ?

  • @maximilianoortigoza9841
    @maximilianoortigoza9841 3 роки тому

    How do I make it also attack the left activating a collision on the left and without activating the right?

  • @kaoslinkcabana
    @kaoslinkcabana 3 роки тому

    Amigo amo este video, mil gracias, me has ayudado mucho ☺️☺️☺️☺️☺️

  • @evohollywood303
    @evohollywood303 3 роки тому

    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

  • @CortexQuart
    @CortexQuart 2 роки тому

    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

  • @mladennikolic4394
    @mladennikolic4394 4 роки тому

    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

  • @Asbjornn
    @Asbjornn 3 роки тому

    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?

  • @beanfox6454
    @beanfox6454 2 роки тому

    Very 👌

  • @Ifrit_desu
    @Ifrit_desu 4 роки тому

    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.

  • @Jorge_super
    @Jorge_super 3 роки тому

    Can i make the AttackArea change with every frame of the attack?

  • @SenatorBrotein
    @SenatorBrotein 4 роки тому

    What is the difference between putting == instead of =???

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      == 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.

  • @lolipopjojo6218
    @lolipopjojo6218 3 роки тому

    Thx 🙏 understood how to am gonna script my player in few minutes

  • @jellybeanconfirmed9049
    @jellybeanconfirmed9049 4 роки тому

    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!

    • @jellybeanconfirmed9049
      @jellybeanconfirmed9049 4 роки тому

      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)

    • @antidevgodot
      @antidevgodot  4 роки тому

      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!

    • @antidevgodot
      @antidevgodot  4 роки тому +1

      @@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. :)

  • @finnwydd
    @finnwydd 4 роки тому +4

    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!

  • @epicswordgaming
    @epicswordgaming 3 роки тому

    can you show us how you coded the jump slash?

  • @lmlstudio2008
    @lmlstudio2008 3 роки тому

    what a life saver!

  • @neobichniymarketplace
    @neobichniymarketplace 3 роки тому +1

    Что делать, если у врага тело не Area2d, а KineaticBody2d?
    What should I do if the enemy's body is not Area2d, but KineaticBody2d?

    • @KoeK_oe
      @KoeK_oe 3 роки тому +1

      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.

    • @neobichniymarketplace
      @neobichniymarketplace 3 роки тому +1

      @@KoeK_oe Hi, yes, I have already solved this problem, but still thank you for your help

  • @69Bruhmoney69
    @69Bruhmoney69 3 роки тому

    how do I make it so if my player hits again after he hit once it will change his hitting animation.

  • @HechiPunK
    @HechiPunK 3 роки тому

    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?

  • @ibi662
    @ibi662 3 роки тому

    hi need help i cant see collision shape 2d in area 2d

  • @jormungandtv5512
    @jormungandtv5512 3 роки тому

    I love your chanel, ths for help

  • @Asbjornn
    @Asbjornn 4 роки тому

    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.

    • @RuaanRuaan
      @RuaanRuaan 4 роки тому +1

      Add
      if is_attacking == false
      In the idle func

    • @RuaanRuaan
      @RuaanRuaan 4 роки тому

      4:38

  • @lilrs9595
    @lilrs9595 4 роки тому

    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!

  • @bryanonce5024
    @bryanonce5024 3 роки тому

    Guys what if I using AnimationPlayer,6:31 what I will change in code animation ?

  • @w.e.a.k.9768
    @w.e.a.k.9768 3 роки тому

    Thank You Sir ^_^

  • @lonewolfprogrammer8932
    @lonewolfprogrammer8932 6 місяців тому

    Thanks alot!!!

  • @rounak3811
    @rounak3811 3 роки тому

    Thanks man

  • @andiartgame
    @andiartgame 3 роки тому

    when you go to the left, how do you make the collision also turn to the left ?

    • @mrtz187
      @mrtz187 3 роки тому

      Create a second collision box and make the other one disabled when you turn to left/right

    • @KoeK_oe
      @KoeK_oe 3 роки тому

      @@mrtz187 make the collision animatedsprite's children and flip animatedsprite using scale.x instead of using flip_h

  • @olegmostepan5960
    @olegmostepan5960 3 роки тому

    Thank you, great tutorial :) that what I was thinking about, how to use animated sprite with mlea attack :)

  • @hddrone5416
    @hddrone5416 4 роки тому +1

    Hola! Como puedo contactar contigo? Un saludo

  • @blenderer3191
    @blenderer3191 3 роки тому

    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.

  • @gilbraltar8857
    @gilbraltar8857 4 роки тому +1

    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