2D Melee Combat in Godot 4 using AnimationPlayer and Collision Shapes

Поділитися
Вставка
  • Опубліковано 9 лют 2025

КОМЕНТАРІ •

  • @nubifist399
    @nubifist399 22 дні тому

    thank you sir

  • @nahuelpaillapi
    @nahuelpaillapi Рік тому +2

    thank you a lot man!!!! now i can finally start to work a lot on my game!!!

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

      No worries, pleased to be of help.

  • @zebini
    @zebini Рік тому +3

    Hey! Nice video!!
    On minute 13:00 you mention that it is not the best way with dealing with the attack animation issue (forcing the animation player to finish playing the attack animation by only allowing walk/idle to play if the attack animation is not playing). The purpose of me reaching your video was precisely how to overcome that issue, and I see that your method works! So thanks for that. However, what would be a better way of approaching that issue? Thank you!!

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

      Essentially the better way is to have a state machine that knows what the player is able to do, is currently doing and all the rules for this.
      Essentially when the player is idle they can change to walk, run, attack, jump.
      www.gdquest.com/tutorial/godot/design-patterns/finite-state-machine/
      You can then tell the animation to blend between the different states (dealing with Animation blending is quite time consuming and there are others out there who have put together far better videos and guides).

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

    thanks man you are the bast

  • @christie8425
    @christie8425 Рік тому +3

    How would collision hurtboxes work when the boss is animated eg. A boss who's head is animated to move around the screen in a spinning effect

    • @learnictnow
      @learnictnow  Рік тому +3

      It will all depend on how you setup the boss.
      Consider the following example boss structure:
      BodyCharacterBody3D
      - Head
      -- HeadCollision
      - Main Body
      -- MainBody Collision
      -- Arm
      --- ArmCollision
      -- Leg
      --- LegCollision
      You could have collision meshes on each part of the body and they would act independently (e.g. allowing for headshots)
      If you want to move the entire boss around the screen animate and move BossCharacterBody3D. Because all of the collision shapes are children (lower in the tree) of BossCharacterBody3D when you move this node / object all of the others move with it. Also if you animate the head the HeadCollision will move with it.

  • @Wancho
    @Wancho Рік тому +3

    Amazing, working 10/10.
    I'm trying to create something like action rpg, can you show how to make the enemy attack me? Ty, amazing video btw.

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

      No worries, I haven't got a 2D version for this but there is a 3D version here (ua-cam.com/video/1XOyr6DMLiM/v-deo.htmlsi=38_hNUhOey0uhlm8)
      I'll try to get something on this.
      Look up NavigationAgents (docs.godotengine.org/en/stable/tutorials/navigation/navigation_using_navigationagents.html)
      Kids Can Code have an example for Godot 3 which will cover the key parts
      kidscancode.org/godot_recipes/3.x/ai/chase/index.html

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

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

  • @robertwilliams2696
    @robertwilliams2696 4 місяці тому

    When I flipped the sprite with the scale.x property, only my sprite flips but not my collision shapes. Unless I missed it in the video, how did you flip the collision when the sprite flips during the attack?

  • @pingu4396
    @pingu4396 8 місяців тому +1

    Page Not Found when clicking your source code man

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

    how can i do it if i have an animated sprite2d with the texture animations? because i can't keyframe from the animated sprite frames so that i am able to see where to put the collision shape. Like the main problem here is that I can see what is currently going on in the animation so that I have to guess where to put the collider or any other thing if i want to.
    Now i am using animated sprite 2d because I have one sprite sheet with all the animations rather than separate file for each of them.

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

    you assigned a group "Enemy", but I have no idea how you created said grp.

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

      Go to the Nodes tab in the inspector (rather than Signals) and you can create groups there and assign other nodes to them.
      docs.godotengine.org/en/stable/tutorials/scripting/groups.html

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

      @@learnictnow ty for this. It's amazing how many little details about this engine I still haven't discovered

  • @thomasmytskidhs2789
    @thomasmytskidhs2789 10 місяців тому

    when i keep the right button pressed while attacking once, the attack animation plays forever until i release the move button xD Any ideas on how to fix that?

    • @giraffewithabowlerhat1883
      @giraffewithabowlerhat1883 9 місяців тому

      It's probably a matter of using "is_action_pressed()" instead of "is_action_just_pressed()". The latter will only trigger on the frame you press the button. The former triggers every frame you have that button pushed down.

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

    would be nice if you minimize the output window to see more of the code on screen, thank you

    • @learnictnow
      @learnictnow  Рік тому +2

      Thanks, I'll take that into account when making more tutorials. Thankfully Godot 4.2 allows you to have a separate code window which means I'll be able to have code filling the entire screen easily.

  • @lucas_pscheidt
    @lucas_pscheidt 9 місяців тому

    Why didn't you use an animated sprite 2d node instead of sprite 2d?

    • @bedang1058
      @bedang1058 8 місяців тому

      Beginner here, but on my first try with an animated sprite I couldnt get the attack animation to work well, then with animations on a "normal" sprite it was really easy

  • @FateflyYip
    @FateflyYip 9 місяців тому

    cool, i want to learn from your scripts, but the link is not working. I want to know how to make a group of enemy so i can check body.is_in_group(Enemy)

    • @giraffewithabowlerhat1883
      @giraffewithabowlerhat1883 9 місяців тому

      Create and edit groups in the nodes tab of the inspector (the same tab with all the signals).
      I prefer using layers and masks though. They're super helpful, and if you set them up correctly, the Areas will only detect what you want them to detect!
      I found this video from Garbaj that's pretty good ua-cam.com/video/ZNcFpDSWRUw/v-deo.htmlsi=USKR0V12eHRV4T0G this applies to PhysicsBodys and Areas