Create Melee Attack / Combat in Unity - P1 - Attack Animation

  Рет қаралды 52,619

Sunny Valley Studio

Sunny Valley Studio

Күн бұрын

Пікірлер: 57
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
Part 2 - > kzbin.info/www/bejne/f2O4oGubetKGfLM
@venogear3159
@venogear3159 11 ай бұрын
I think I did something similar once, forgot, watched it in rewind mode for 5 minutes and remembered everything, thank you!
@SunnyValleyStudio
@SunnyValleyStudio 11 ай бұрын
Awesome! Thanks for the comment 🙂
@zapleaf
@zapleaf 2 жыл бұрын
You liked a comment I made on a video of yours and so I thought I'd browser your channel. And OMG.. you have so much good content, and your energy is so fun and charming. I'm now a fan. Keep being you!
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
Thanks!
@cormacisawesome
@cormacisawesome Жыл бұрын
really helpful tutorial im making an rpg however i struggled with top down combat. this video was really clear and now i know how to do it :)
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Thanks for watching! 🙂
@looeehg2490
@looeehg2490 15 күн бұрын
Great video well presented and thought out. just thought id ask why not have a private Animator [serializable] and also on the same you should null check it.
@jamescriddle9312
@jamescriddle9312 Жыл бұрын
Great tutorial! Thanks for this!
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Glad it was helpful! Thanks for watching! 🙂
@brandonjacksoon
@brandonjacksoon 2 жыл бұрын
Thank you mister! You have a really helpful tutorials!!!
@ProgressshGames
@ProgressshGames Жыл бұрын
Very helpful video, thanks!
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Thanks for watching! 👍
@김익환-o4m
@김익환-o4m 2 ай бұрын
Best video.!! When the character moves up or down, the weapon shakes. Why is that? :(
@SunnyValleyStudio
@SunnyValleyStudio 2 ай бұрын
If I recall correctly we use animator to animate the weapon? The idea is that the weapon follows the parent "agent" object and its local position is controller by the animator. As far as I can tell the only thing that affects the position of the weapon - that can make it shake is how you set up the animation itself. This kind of thing often happens when you try to make an object follow your object by setting its position through the script while you also use Animator to control its position. Since the animation overrides the position the object teleports. That is why we parent it to make it follow the Agent.
@lukemarkbrady
@lukemarkbrady 6 ай бұрын
Great stuff as always. Been following your tutorials as they are so clear. Now I'm looking to implement a weapon swap feature so the player can switch weapons to another sword. Any suggestions how to achieve this?
@SunnyValleyStudio
@SunnyValleyStudio 6 ай бұрын
What I would suggest is to have a database (or simple a list of SO where you store references to the weapon related data ana prefab of a weapon). I would use separate prefabs because melee has the swing aniamation but a gun would have something different. So it might be easier to just swap a prefab that is a child of the WeaponParent object. I would keep the Input connected to the WeaponParent object and the WeaponParent would check "if I have weapon - > use it". Next just create a new script that we could call to "Swap" the weapon prefab and send the new weapon reference to the WeaponParent. Should be fairly simple to implement 🙂
@amritsahani69420
@amritsahani69420 2 жыл бұрын
It helped a lot never give up💪
@brandonjacksoon
@brandonjacksoon 2 жыл бұрын
Best of the best ;)
@luxe1098
@luxe1098 4 ай бұрын
after i attack the weapon stops following my mouse movement, why is that?
@SunnyValleyStudio
@SunnyValleyStudio 4 ай бұрын
It can be animation related. I recall that we had set the Animator on the weapon ? If so if the animation doesn't loop and stays in the "swing" animation (I don't remember how we have called it exactly) the animator directs the position of the weapon - overriding your input. So my best guess is that the animation never transitions back to "idle" state in the weapon animator / player animator. I hope it helps!
@ggnouhiiam
@ggnouhiiam 4 ай бұрын
the delay is not really working, i can still spam my attacks even though it's running through the coroutine
@SunnyValleyStudio
@SunnyValleyStudio 4 ай бұрын
Interesting. Well maybe I have messed something up in the explanation. I have used this a few times and usually it works out great. Especially when you use something like State pattern to separate states. Maybe its just that despite the delay some other code that triggers attack again runs? Like some "bool" flag check is missing?
@ggnouhiiam
@ggnouhiiam 4 ай бұрын
if im correct then you can set the delay to any amount and you can still spam it
@SunnyValleyStudio
@SunnyValleyStudio 4 ай бұрын
@@ggnouhiiam The idea is that you connect input with logic that triggers the attack. Next you block the trigger and use a delay to unblock it. The only way to spam it would be if the trigger is not blocked. In that case the delay indeed doesn't matter. That is why I think it might be a simple bug in the code where the bool flag is not set if is not blocking the trigger.
@ggnouhiiam
@ggnouhiiam 4 ай бұрын
yeah i figured it out when i saw the block attack
@mikrofon10000
@mikrofon10000 Жыл бұрын
Really helpful information! getting into game development myself and im working on my second project! I was able to figure out how to get the weapon moving by using the old input system, However the code line Animator.SetTrigger("Attack"); says the following error: An object reference is required for the non-static field, method, or property 'Animator.SetTrigger(string)' Assembly-CSharp I tried looking around for a solution but no luck so far, would it be because since you use the new input system I will need to write the code differently? Thanks again!
@mikrofon10000
@mikrofon10000 Жыл бұрын
Nevermind, after an hour of looking through i realized that the code line was with a Capital A and not animator..... Feel really stupid now lol
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Don't worry about it. I did that mistake couple of times myself when I was starting out with programming. Good job at finding the bug yourself 👍
@정동우-n2x
@정동우-n2x Жыл бұрын
Personally, I get an error in this code. The errors are as follows. 1. IsAttacking is applied from the beginning with true, so if you don't press the attack button, you don't follow the mouse pointer. 2. And personally, I don't know if I made a mistake, but using Event Animation Helper, ResetIsAttacking does not result in false..
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Sorry to hear that. It sounds like it could be an error in the code (somewhere it the logic). You can grab the code and a full project from my Pateron (this is for the Context Steering tutorial but it hase the same animation / attack setup) www.patreon.com/posts/context-steering-68964987
@정동우-n2x
@정동우-n2x Жыл бұрын
@@SunnyValleyStudio Ok, I joined
@efematt292
@efematt292 Жыл бұрын
Im trying to make the player stop every time it attacks, so it wont keep running while attacking, but i cant find the way to make it work, can someone help me?
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
I usually use state pattern to split the different actions that the character can do. I show it my my design pattern course courses.sunnyvalleystudio.com/p/code-a-2d-platformer-game-in-unity-using-design-patterns In general the idea is that when you press the attack button you want to set velocity to 0 and cut the input from the movement system until the end of attack animation when you again allows the player to affect the player movement.
@c4bleturn438
@c4bleturn438 Ай бұрын
does this process work in bow?
@SunnyValleyStudio
@SunnyValleyStudio 29 күн бұрын
For a bow you would remove the animation and instead trigger your own "bow pull" animation or just instantiate an arrow where the bow is. The movement would be the same
@LowGuyy
@LowGuyy Жыл бұрын
Does this work for side scrollers like something like hollow knight?
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
It is a generalized setup for a 2D game. It should work but as I have used a similar setup to make a 2D platformer courses.sunnyvalleystudio.com/p/code-a-2d-platformer-game-in-unity-using-design-patterns
@chunlam7283
@chunlam7283 2 жыл бұрын
hello, thanks for the very nice video. i get a question here. when i perform the attack if the weapon is on the right side of my player it works fine. but when the weapon is on the left side of the player the weapon attack animation still play but the animation of attack is back to the player side not in front of the player.
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
Did you use Transforms X scale value (I think) to flip the sprite or flip horizontally on the sprite itself? Maybe I don't fully understand the question but the idea is that if we use scale the animation should be player in reference to the transform position / scale of the weapon parent and the weapon object. I can't say that I am experiencing the same issue in my project. If you want to support me and get the full project with the attack logic implemented you can become my patreon (and you would be helping me a lot) www.patreon.com/posts/context-steering-68964987?
@AlexD_20
@AlexD_20 Жыл бұрын
had the same problem. I guess your player also looks in the direction of your input keys instead of looking to your mouse right? if yes then respond to this and Ill paste the code for the weapon
@carlabalos3884
@carlabalos3884 2 жыл бұрын
Could you do a combo attack for this one too like one slash after another? Would really be helpful.
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
I will see what I can do. First I want to tackle context steering ai
@carlabalos3884
@carlabalos3884 2 жыл бұрын
@@SunnyValleyStudio Thanks
@durrium
@durrium 2 жыл бұрын
Somehow there is no posibility to drag in the sprite into the animation window. Strange!
@durrium
@durrium 2 жыл бұрын
EDIT: Had to choose the gameobject in the hirearchy to add sprites!
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
I'm glad that you have been able to figure it out!
@Al-Asire
@Al-Asire Жыл бұрын
I need the code to download it if you can thank you
@SunnyValleyStudio
@SunnyValleyStudio Жыл бұрын
Here are the scripts github.com/SunnyValleyStudio/Melee-combat-system-Unity-2D
@henrysharingan
@henrysharingan 2 жыл бұрын
What about combos?
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
I am just working on a project with combos! Maybe I will be able to create a tutorial about it :) Thanks for a suggestion!
@n0n3x
@n0n3x 2 жыл бұрын
Does this work for 3D?
@SunnyValleyStudio
@SunnyValleyStudio 2 жыл бұрын
You could use a Physics.Raycast instead or use on of the 2d detectors / add a collider on a 3d weapon model + a kinematic rigidbody. The code would be the same but the detection method will really depend on the type of a game you are making.
@n0n3x
@n0n3x 2 жыл бұрын
@@SunnyValleyStudio alright, thanks a lot!
@im_an_intern_unity_dev
@im_an_intern_unity_dev 5 ай бұрын
comment
@SunnyValleyStudio
@SunnyValleyStudio 4 ай бұрын
I'm sure it will make YT algorithm very happy 🙂
@im_an_intern_unity_dev
@im_an_intern_unity_dev 4 ай бұрын
@@SunnyValleyStudio haha
Create Melee Attack / Combat in Unity - P2 - Hitting objects
14:03
Sunny Valley Studio
Рет қаралды 15 М.
Pixel Art Class - Attack Animations
51:22
AdamCYounis
Рет қаралды 284 М.
ПРЯМОЙ ЭФИР. Золотой мяч France Football 2024
4:41:06
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,9 МЛН
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 30 МЛН
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 12 МЛН
Escaping Unity Animator HELL
18:18
Lost Relic Games
Рет қаралды 513 М.
I Built Skyblock In Minecraft Hardcore
23:40
Beppo
Рет қаралды 343 М.
Creating SMART enemies from scratch! | Devlog
5:40
Challacade
Рет қаралды 350 М.
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,2 МЛН
Unity - 2D Melee Combo System Tutorial
22:15
Sean Masai Hill
Рет қаралды 75 М.
MELEE COMBAT in Unity
21:07
Brackeys
Рет қаралды 1,6 МЛН
Professional animator works on subscribers' Unity games for free.
22:20
Lightsaber Battlegrounds game is unexpectedly fun
8:10
Sketch
Рет қаралды 138 М.
Pixel Art Tips from a Professional Artist - Tips & Tricks
8:01
Goodgis
Рет қаралды 1,1 МЛН
ПРЯМОЙ ЭФИР. Золотой мяч France Football 2024
4:41:06