Melee Combat System in Unity 2D (With Targeting!)

Поделиться
HTML-код
  • Опубликовано: 28 дек 2024

Комментарии • 91

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 года назад +6

    Check out this Melee Combat System which is exactly what I used in Hyper Knights!
    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php

  • @hanzflackshnack1158
    @hanzflackshnack1158 4 года назад +7

    Concise information as always. Someday could you cover how to code a combo system with precise inputs I.E. Marvel Vs. Capcom, Tekken, Skull Girls etc except in a top down format? Thanks for these CM! you're the best.

  • @loldude8238
    @loldude8238 2 года назад

    You're so underrated. I love your tutorials, thank you so much.

  • @techbytefrontier
    @techbytefrontier 4 года назад

    ty for the tips for each video, very helpful

  • @JTAGames
    @JTAGames 4 года назад +1

    Love the video!

  • @457Deniz457
    @457Deniz457 4 года назад +1

    So nice ! Thanks ! :)

  • @Danny1y5
    @Danny1y5 2 года назад

    On 16:00 when I try to spawn enemies, the object being instantiated is null. Which I think is because of GameAssets.i.pfEnemy. I have the GameAssets script, do I put it on the enemy or spawner object? Both don't work for me when I assign the prefab to pfEnemy.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      Make sure you're assigning the reference on the GameAssets prefab, not the object on the scene. Or assign it to the object on the scene but then also save the prefab
      Depending on the script order execution it might use the object in the scene or it might instantiate a new GameAssets prefab.

    • @Danny1y5
      @Danny1y5 2 года назад

      @@CodeMonkeyUnity It still seems to come up as null when assigning the reference with the prefab. I've tried putting the prefab in a "Resources" folder too but nothing seems to work.

  • @pekrupienyu2916
    @pekrupienyu2916 4 года назад +3

    Hi code monkey, great tutorial. I got a question. Why do we use this approach over using 2D colliders on the individual enemies? I understand this current game where there are lots of enemies this approach is objectively better but say for a game with 1v1 fights would it be better or worse to use 2D colliders instead?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +5

      Sure you can place a collider in the attack position and look for what it hits, or even better just do Physics2D.CircleCast();

    • @pekrupienyu2916
      @pekrupienyu2916 4 года назад +1

      @@CodeMonkeyUnity cool. Appreciate the reply

  • @xerodeus2337
    @xerodeus2337 3 года назад +1

    Pretty new to this, just getting started - does this use the new input system from Unity? or the old one?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      It uses the old input system but you can easily convert it, the melee logic is the same

  • @juicedup14
    @juicedup14 Год назад

    are your animations basically 8 cardinal direction?
    or are they procedural animations?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      They are 8 animations, made using my mesh animation system unitycodemonkey.com/video.php?v=11c9rWRotJ8

  • @drspandau8350
    @drspandau8350 4 года назад +2

    Can you please make a tutorial for this Character Base animation thing?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Yes I covered it here ruclips.net/video/11c9rWRotJ8/видео.html

  • @あれくす
    @あれくす 4 года назад +1

    Can you make a video on weapon system as part of player attack? Maybe how equipment can be accounted for into the player attack and animation system? For example, melee attack verse ranged attack versed caster magic? One uses a sword, the other a bow, and the last magic which may or may not have a weapon equiped?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Depends a lot on how you set things up, you need to break that problem into smaller pieces, first handle the animations, then handle the sprites, then handle unit stats and so on.
      ruclips.net/video/isAmoM3RPEI/видео.html

  • @-Constantine-
    @-Constantine- 2 года назад

    hey man nice videos tyou have there.
    I have a question: is there any isometric real time arpg and mouse movement controlled (diablo-clone) with freeflow combat mechanics? (like shadow of war , assassins creed etc) Im looking for nice and many animations, counter attacks and that smooth cinematic/acrobatic feeling . ty in advance.

  • @KennyComicx
    @KennyComicx 2 года назад

    Hi, how do i go about making the character face the attack direction after an attack instead of snapping back to its last moveDirection. I've been stuck at it for hours and can't seem to figure it out. Thanks :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      That depends heavily on what animation system you're using, but you would just basically store a Vector3 for the lastAttackDirection and default to that animation while not moving.

  • @neozoid7009
    @neozoid7009 2 года назад

    hey CM I have one more question why did you return an Enemy when creating an enemy . I found out that it is also possible to create an object without retuning anything in some cases , can you please explain it to me it would be very helpful for me. thanks And also why did you instantiate a transform and not a gameobject ??

  • @neozoid7009
    @neozoid7009 2 года назад

    CodeMonkey I have one Question why did you take attackPosition = (transform.position + mouseDirection ) ? mathematical explanation .

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      In order to attack towards the mouse
      So if you click above and to the right of the character it will find hte closest enemy in that direction, if you leave the player in the same position and click under and to the left it will find another enemy in that direction

    • @neozoid7009
      @neozoid7009 2 года назад

      @@CodeMonkeyUnity Thanks I got it.👍 But How transform.position + mouseDirection leads to mouse direction ? Addition of a position vector and a direction vector leads to the direction vector , but how??

  • @christopherdoiron4294
    @christopherdoiron4294 3 года назад +3

    This is the only video on the internet I can find that explains how to targeted melee attacks, yet, if you follow this tutorial, you'd have to write an entire library of other utilities and animation scripts. Each one with leads back to previous videos. At this point, trying to get my character to have targeted melee becomes useless because I might as well just pretend my game is your game. Solution: is there a simpler way of rotation an animation from the animator?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      The logic for finding the target is what matters, calculating the direction and identifying nearby objects, that logic can work with any animation system you want.

    • @AkashKumar-gu7jc
      @AkashKumar-gu7jc 2 года назад

      Well, you could take this video as an inspiration and try to implement it in your game, the key is the ability to learn from ideas and make your own solution.

  • @darkman237
    @darkman237 4 года назад

    What if you wanted to scroll the combat text on a panel?

  • @gamerrepublicof4726
    @gamerrepublicof4726 3 года назад

    Code MonKey!! you are always the best, will you consider making a top down shooter game like Archero??

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      I'm not familiar with that one but I did do a Top Down Shooter a long time ago ruclips.net/video/Eyx3EfqqfMw/видео.html

  • @FyresGames
    @FyresGames 4 года назад

    Do you have a rear attack? I mean extra damage if you hit the enemy from behind?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      If you have a vector to where the enemy is looking at and you have the player position you can calculate the Dot product and if its < 0 then the player is behind

    • @FyresGames
      @FyresGames 4 года назад

      @@CodeMonkeyUnity I did your turn based battle system. Does it have that in the scripts?

  • @DRATER469
    @DRATER469 Год назад

    Does anyone know the video where he shows how the attack is animated?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +1

      MY animation system is based on dynamic meshes unitycodemonkey.com/video.php?v=11c9rWRotJ8

    • @DRATER469
      @DRATER469 Год назад

      @@CodeMonkeyUnity ahh i was hoping that wasnt the case. Cant wrap my head around that one for some reason. Ill give it another go!

  • @djdatore
    @djdatore 3 года назад

    Hey there, I am rather new to unity and was hoping to find a better way(then with timers) to let the attack animation finish before returning to idle. I don't want to manage timers for every attack(if possible). Appreciate your guidance thanks!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      You could just make a proper timer class with some simple exposed functions to start a timer and get a callback.
      Something like: public void StartTimer(float time, Action onTimerElapsed);

  • @deeptiyadav923
    @deeptiyadav923 4 года назад

    Hey can you make armor tutorial

  • @mehmedcavas3069
    @mehmedcavas3069 4 года назад +6

    Hey code monkey what about a 2d Minecraft game like terraria with simple inventory and crafting system. A small series would be great

    • @lethn2929
      @lethn2929 4 года назад +2

      As it turns out he's already done a crafting system tutorial.
      ruclips.net/video/LmQ6U3YkHHk/видео.html

    • @mehmedcavas3069
      @mehmedcavas3069 4 года назад

      Violet twd hey dude 😊👋🏻

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Yeah a Terraria like game is something I was actively working towards but I haven't covered many sidescrolling systems yet so I had to postpone that project.
      I was preparing for a normal Top Down Survival Crafting game but then got caught up with the DOTS update so haven't been back to it.
      There's lots of cool stuff I want to make, just not enough time to do them all!

  • @subliminalcastillo2126
    @subliminalcastillo2126 4 года назад

    You know a game dev doesn't fuck around when he codes in every single mechanic in his games.

  • @gower1973
    @gower1973 4 года назад

    Isnt it bad practice to just allow the player to spam the mouse to attack, wouldnt it be better to have a timer to limit the number of attacks, like attacks per second or some such mechanism.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +4

      Depends on what type of game you're making. If it's meant to be like Dark Souls then you should let the animation play fully, if it's meant to be fast paced you can let the player attack at every click.

  • @ozancobanoglu812
    @ozancobanoglu812 4 года назад

    I'm Thinking This Camera Is Cool But But Most Of The People Wants To Create Complete Platformer / metroidvania but unfortunately most of the tutorials are incomplete I wish you can make some on udemy or on RUclips

  • @KalponicGames
    @KalponicGames 4 года назад

    how do you make a player jump in 2D top-down game?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Depends on how you want to implement it since there's no "natural" way to display that

    • @KalponicGames
      @KalponicGames 4 года назад

      @@CodeMonkeyUnity can you make a video of how to do it? Also I am unable to reach you for some questions I had. Do you provide any tutoring?

  • @nathan12581
    @nathan12581 4 года назад

    Tutorial on your ‘animation system’?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      It's based on dynamic meshes, I covered it here ruclips.net/video/11c9rWRotJ8/видео.html

  • @FIFAGLITCH
    @FIFAGLITCH 4 года назад

    Hi
    do these codes work on mobile or only windows and linux?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      The only difference between Desktop and Mobile is the Input method changing from Keyboard to Touch. Everything else is the same

    • @FIFAGLITCH
      @FIFAGLITCH 4 года назад

      Code Monkey Hi
      So i should copy your toturial and it will work?
      And what is the input method?

  • @OutBoy12123
    @OutBoy12123 4 года назад +1

    Hey Code konkey I really need your help I want to make a combat system that makes you go in combat mode when you click a button so like there are two modes one for combat other for pasif actions Please Help ı really need this

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Sounds like you need to define a State machine. I covered something similar in the Enemy AI video ruclips.net/video/db0KWYaWfeM/видео.html

    • @OutBoy12123
      @OutBoy12123 4 года назад +1

      @@CodeMonkeyUnity Yes! THANK YOU but can I define the same thing for the player and not with AI instead with a input button I am fairly new to unity and you are the best at teaching

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      @@OutBoy12123 Sure, instead of switching states automatically you do it when the player presses a button

    • @OutBoy12123
      @OutBoy12123 4 года назад

      @@CodeMonkeyUnity Thank you so much You are the best out there about this topic also my game dev idle

  • @sonicherores
    @sonicherores 4 года назад

    A quick question When I go to Instantiate(GameAssets

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      That class was made here ruclips.net/video/7GcEW6uwO8E/видео.html

  • @husejinbg
    @husejinbg 4 года назад

    What is your camera size ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      About 70, the number itself doesn't matter, it's all relative to the size of your objects.

  • @sovietonionisthebestonion3805
    @sovietonionisthebestonion3805 4 года назад

    Can you make your player jump ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Sure ruclips.net/video/ptvK4Fp5vRY/видео.html

  • @sgillespie00
    @sgillespie00 4 года назад +1

    Your videos are so awesome, but I have to know: are you really typing in real time?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Usually I speed up the sections where I'm just typing and not talking in order to keep the video flowing. But when I write and talk at the same time yeah that's my normal typing speed. Been writing code for 20 years!

  • @nontasng8068
    @nontasng8068 2 года назад

    The codemonkey utils have a lot of errors
    I dont know what to do

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      What errors?

    • @nontasng8068
      @nontasng8068 2 года назад

      @@CodeMonkeyUnity Camera errors mostly in util folders

    • @nontasng8068
      @nontasng8068 2 года назад

      @@CodeMonkeyUnity Also I would love a video
      explaining the codmonkey utils
      I prefer learning without using utils and packages

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      ​@@nontasng8068 Are you talking about the Utils or project files?
      The project files uses Cinemachine, but the Utils themselves don't need anything.

  • @lethn2929
    @lethn2929 4 года назад +5

    I love how I did all this research on how to do 2D targeting with a mouse, implement it and then fucking Code Monkey comes along with a tutorial explaining it all in exactly the same way :( he's as bad as Brackey's, he's even doing the same maths to make the raycast accurate.

    • @457Deniz457
      @457Deniz457 4 года назад +1

      Lel.. so ur mad bcs u "wasted" time or bcs of that others can do the same thing in a fraction of the time u had invested?^^

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +5

      It's very important to develop the skill of doing your own research so all the time you spent wasn't wasted!

    • @457Deniz457
      @457Deniz457 4 года назад

      @@CodeMonkeyUnity Yes ! :)
      Thats why I said "wasted" :P

    • @lethn2929
      @lethn2929 4 года назад +1

      @@457Deniz457 Yes exactly lmao, I don't hold it against them, this is how technology and coding works but it is such a piss take when a video for my problem gets uploaded moments later. I think it was actually a couple of days ago I dealt with the issue and had to find some obscure unity forum post on google of course.

    • @457Deniz457
      @457Deniz457 4 года назад

      @@lethn2929 Well I feel you.
      I also have to struggle thing where I know in 1-2 years everone can quick google it ... xD