2D Melee in Unity Tutorial

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

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

  • @adhoahsgamingdnd9617
    @adhoahsgamingdnd9617 Год назад +3

    I've been working on a top down rpg game with waves of enemies, and your videos are always a nice insight on how some of these mechanics can be done and I always enjoy them!

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

      Woo! I'm happy to help! 💪

  • @yukiyukihanma
    @yukiyukihanma 10 месяцев назад +7

    for the sword to swing in the mouse position
    mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
    float angle = Mathf.Atan2(mousePos.y-transform.position.y, mousePos.x-transform.position.x) * Mathf.Rad2Deg - 90f;
    transform.localRotation = Quaternion.Euler(0, 0,angle);
    add this to playerinput

    • @obi_ladd1405
      @obi_ladd1405 9 месяцев назад

      this also rotates the player.

    • @sigma9.90
      @sigma9.90 3 месяца назад

      @@obi_ladd1405 lock z rotation on your player character

  • @dusklightcreations3951
    @dusklightcreations3951 Год назад +2

    You working on 2d top down series is helping me to work on some mechanics for little adventure I hopped into.

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

      Awesome! I'd love to see it when you finish it!

  • @doggo2031
    @doggo2031 11 месяцев назад +5

    I have a question, in your demonstration, your sword swings in the direction of your mouse, when I used it, it would swing in the set direction. IS there any fix to this?

  • @scoliosis430
    @scoliosis430 Год назад +5

    Everything here is perfect, but I have a question, in your demonstration, your sword swings in the direction of your mouse, when I used it, it would swing in the set direction. Can you tell me what I'm doing wrong please?

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

    Thanks for making my suggestion so quickly. Very impressive.

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

      Hey if you ask, you get it!! Thanks for watching!

  • @jezreelmarkbarrameda8287
    @jezreelmarkbarrameda8287 10 месяцев назад +1

    mine can only attack on one side and i dont know how to fix it

  • @XulinBr
    @XulinBr 11 месяцев назад +1

    BRO HOW THE SWORD IS GOING WITH YOUR MOUSE POSITION

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

    Good video, but you left out the part where the sword attack changes direction with the mouse.

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

      how do you fix this?

  • @gececiyim87
    @gececiyim87 Год назад +3

    hello, when I click the mouse, the sword swings from the same place. So it doesn't shake in the direction of the mouse. What is the reason?

    • @csongorbalassa5724
      @csongorbalassa5724 Год назад +2

      I am having the exact same problem right now, did you manage to solve it? Or anyone?

    • @moronji4755
      @moronji4755 Год назад +3

      I am also having the same problem did you figure out how to fix it?

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

      same probleme here

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

      same here

    • @boa-cn1hu
      @boa-cn1hu 2 месяца назад

      cause its based off player rotation, which he didnt include

  • @teppidd
    @teppidd Месяц назад +1

    Hi Everyone! After much hair pulling and a helpful hidden reply in here:
    In order to fix the issue of the sword only swinging once, you must change the Update() function a little.
    **after the tutorial I had it as:*
    private void Update()
    {
    if(timeUntilMelee

    • @Cato202
      @Cato202 15 дней назад +1

      Hey thank you so much i was lost Also for the actual code its anim not _animator

    • @teppidd
      @teppidd 14 дней назад

      @@Cato202 lol sorry I changed the variable, but I'll change it back for this comment! :)

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

    Hi, i have a problem with the sword animations when i attack it only goes halfway the animation

  • @dusklightcreations3951
    @dusklightcreations3951 Год назад +2

    So have you consider to to work on in game shop system,like having npc to trade with or something similar.

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

      Hell yeah! Do you mean like a Minecraft style trade?

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

      @@MuddyWolf yeah, could think of like that

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

    Good video! I noticed the trail looks like it's still zipping back to the start position at the end of the swing. How do you prevent that?

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

      Hmm good point, the ideal solution would be to keep the sword at the end of the swing once finished, I'm sure you can set the animation to end and keep the position 🤔 I'll do a Google and write a comment if I find the solution

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

      I know this is late, but what I did to fix this was end the trail effect 1 frame before I stopped moving the sword in the animation.

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

    how can i make it so i get to next level when all enemies are killed

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

      make 2 int variables: "killcount" and "necessaryKillcount", set the first to 0 and the second to the number of enemies. Increase "killcount" by +1 on any enemy death. On update check if necessaryKillcount=killcount and if it does load the next scene

  • @sigma9.90
    @sigma9.90 3 месяца назад

    when I set the melee speed to anything above 0 I'll be able to swing once before it stops working

    • @christerry1121
      @christerry1121 Месяц назад

      same

    • @teppidd
      @teppidd Месяц назад

      just posted this comment but I'll put here.
      In order to fix the issue of the sword only swinging once, you must change the Update() function a little.
      *after the tutorial I had it as:
      private void Update()
      {
      if(timeUntilMelee

  •  Год назад

    I loved the video, hello friend, can you guide me with something, I'm making a combo of attacks from a 2d game but the character has 8 directions and in each direction it has an animation that I want to turn into a combo of attacks when clicking release several attacks, you can guide me. I understand that it is with events in the animations. thank you so much

  • @DragoTheSpider
    @DragoTheSpider 8 месяцев назад +5

    for anyone who wants it to follow the cursor just attach this piece of code to a script and attach the scrip to the parent of the weapon no i dont mean the player.
    Vector3 mousePos = Input.mousePosition;
    Vector3 screenPoint = Camera.main.WorldToScreenPoint(transform.position);
    Vector2 offset = new Vector2(mousePos.x - screenPoint.x, mousePos.y - screenPoint.y);
    float angle = Mathf.Atan2(offset.y, offset.x) * Mathf.Rad2Deg;
    angle -= 90; // Adjust the angle by 90 degrees
    transform.rotation = Quaternion.Euler(0, 0, angle);

    • @sigma9.90
      @sigma9.90 3 месяца назад

      tried this, did not work

  • @AquaTwist_
    @AquaTwist_ 9 месяцев назад

    Unfortunately since my game doesn't use the mouse I had to create a Blend Tree to properly rotate the animation depending on the direction the player is facing, like how you would with a Walking blend tree. Great video regardless, it was very helpful! :)

    • @teppidd
      @teppidd Месяц назад

      Would you by any chance be able to explain how you accomplished this?

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

    Hi! This is actually a request from your previous bow combat tutorial but I’m posting it here to make sure you see it!
    So I really need some help, I’m struggling to make it so that instead of the bow and arrow shooting at the direction of your mouse, it shoots *depending on the arrow key you press.* So that means pressing the up arrow key would make it to shoot up, the down arrow key would make it shoot down, Left arrow key would shoot it left and etc.
    *_Of course you’d have to consider making the bow rotate before the arrow shoots too._*
    Please would you be able to help me with the code for this? I’m very new to unity and I’ve been stuck doing this for days now

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

    idk what to do mine is only swinging once and that's it, i have to restart the game but it still does the same thing

    • @Timo-gj5qq
      @Timo-gj5qq Год назад

      I have the same problem...

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

      @@Timo-gj5qq same here, did someone manage to work around it?

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

      same

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

      Sorry you're all experiencing this! If any of you want help fixing it feel free to jump on my discord server and create a post in the forum and I'll try help out!

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

      @@MuddyWolf why cant you tell here?

  • @outhander3941
    @outhander3941 11 месяцев назад

    this is an interesting idea but should framerate fall and you won't hit anyone

    • @sigma9.90
      @sigma9.90 3 месяца назад

      try putting the code to swing and detect damage in fixed update rather than update

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

    Great vid

  • @yukiyukihanma
    @yukiyukihanma 10 месяцев назад

    niceeeeee

  • @rafyfajarramadhan384
    @rafyfajarramadhan384 12 дней назад

    11:12

  • @codeninjasch1105
    @codeninjasch1105 Месяц назад

    bruh