Melee Combat & Weapon System - Unity Beginner Tutorial
Вставка
- Опубліковано 28 вер 2024
- Use Code: ZYGERNY22 for an extra 10% off at checkout
prf.hn/l/K9D1xV8
Assets Used In The Video:
on.unity.com/3...
on.unity.com/3...
In this beginner easy tutorial I will show you how to make a melee system for your game. This tutorial will cover how to create the mechanics of the weapon, animations and how to make it work in actual combat. I will go over how to deal damage with the weapon to enemies and how to set those enemies up. This is a more in depth tutorial as I wanted to give you the foundations of your melee system that you can use in your own game.
At the end you will have an awesome universal melee system. That can be changed and easily implemented into your project.
Discord: / discord
Instagram: / gabzxd
Twitch: / officialzyger
Twitter: / zygerdesigns
➤WISHLIST MY GAME: store.steampow...
Video Sponsored By Unity
Amazing content Zyger, really comphrehensive and clear. We love to see it ❤!
lol its actual unity
omg real unity
nice ad
Ya love to see it
You guys are awesome I haven’t seen anyone support their creators like this
OH MY GOD I WANTED TO DELETE MY WHOLE GAME BC I COULDNT GET THE ANIMATIONS TO WORK
I HAVE BEEN LOOKING FOR A SOLUTION FOR TWO WEEKS
YOU'RE THE BEST
I’ve been a fitness coach for 15 years. I know nothing about game development, and I’m starting to learn. Although I’m new to game dev, I am quite experienced at teaching. You are very good teacher! Subscribed!
overall, good AttackCoolDwon... ok well - but the wp vs. wc oversight *egads* - beginner's are having enough trouble as it is - also, showing making the "Attack" trigger in the Animator Controller instead of having it prepopulated like was done later for "Hit" trigger demonstration - would have been better teaching practice. But hey. Only a teacher like me would maybe nitpick on things like this
This was a great tutorial! For anyone confused with coroutines I encourage you to look into it. But, if you still can't wrap your head around it just yet don't get frustrated. You can also use the animator to turn on and off the weapons collider as a hack-y solution. Thank you, Zyger for making the video. I never would have thought of making the weapon hit box bigger to hit the enemies and would have spent a lot of time wondering why it wasn't working haha.
Every time I press the attack button, it does not work, what do I do? Is there a way to change the attack button to the space button?
I have never done any coding but i feel like i learned something from this. Great video.
You are missing out bro you never wrote any code??
omg
I see you started looking into Coroutines to make your life easier.
They make your processes waaaaay easier :D
Will be using the lessons here to integrate into my own game, thank you so much for posting this.
exactly what i was looking for
You know you’ve peeked when unity sponsors you
fantastic, it helped me a lot to understand animation in unity. Thanks for making this video! ;)
Thank you so much I'm just starting out and this is super helpful.
I have a slight problem, when my weapons box collider already collides with the enemys before i attack, nothing happens when i acctually do attack. I might have done something wrong. It works normally when the weapon box collied does not collide with the enemy before.
Thank U Soo Much I needed this for my first Game the only part im stuck in is in the animations ahah
Really well explained, thanks for that! I tried using your method with a third person controller, and I actually got it done working quite well. I'm struggling to get a decent attack combo system done though. I tried to make a transition between the first hit animation and the first combo hit animation just like you did with the first one, using the previous attack trigger as a trigger for the second transition, but I can't seem to get it done. You would have to click LMB in just the right moment to get the transition done and sometimes for some reason the animation gets stuck and won't transition to an other animation for a very short moment(
i have the exact same issue
Thank you soo much! Finally got the animations working!
I will give you credit on my game's demo! thnk sooo much
Awesome video, neatly explained!
Hey great video but i wanted to make it so that when i attack that the camera shakes a little idk how to do that i could really use your help.
just make a camera shake script and call the shake function when you press your attack button. Brackeys has a great video on camera shake: ua-cam.com/video/9A9yj8KnM8c/v-deo.html
Awesome video Gabi. "Cooldwon" caused my OCD to flare up and I almost got an aneurism, but apart from that 10/10.
great tutorial. but at the end the coding doesn't work for me as the last minute. So at 19:01, when I type wc.IsAttacking)
, an error called ' Assets\Scripts\CollisionDetection.cs(12,39): error CS1061: 'WeaponController' does not contain a definition for 'IsAttacking' and no accessible extension method 'IsAttacking' accepting a first argument of type 'WeaponController' could be found (are you missing a using directive or an assembly reference?)
great tutorial but I hate coding :(
do you have a variable under the name "IsAttacking" ? is that how its spelt ? is it accessible ? That error basically says that this variable is either not accessible or doesn't exists ( which is usually due to spelling or the protection level of the variable)
Thanks a lot this really helped me!
This is a great tutorial, but I was laughing for part of it because the players capsule looks like a turd. xD
Hi uhm im hoping you'll respond to this, the tutorial is really helpful so far but one tiny problem that i've been stuck on is,
when i'm preparing to use the animator. No matter how many times I drag the animation into the animator- nothing seems to pop up?
Did I do something wrong?
I've tried clicking to select the Sword-Attack/Sword-Idle then dragging it, dragging it without selecting it and nothing.
This is actually a unity bug and had been for a while. I reccomend resetting unity and reopening the project. Worst case scenario you might need to re install it. But before that make sure yoy actually have the object with the animator component selected.
@@ZygerGFX Thank you so much! I did what you said and made an entirely new project and repeated the same steps in the video and it works! Thank you so much for responding! ;D
Love the tutorial! Not sure if anyone else has run into this problem too but the Hit animation where the enemy gets knocked back after being hit, sometimes plays twice? tried a few different things but can't figure out whats causing it? I basically done the scripts just as the ones in this video.
hey zyger question, can i use this code combined with the code for pick up and throwing gameobjects (melee weapons)?
*i dont really have a code for a pick up and throw gameObjects i just had a thought for picking up weapons and being able to use them (like you did here) and also being able to throw them for long range dmg option*
it stays in the position that i finished the animation so when i click to attack it reverses from left to right. I made the animation go from right to left. can somone pls help?
Thank you very much :)
Thank you very much! You are a hero!
Nice video it really helped me out, but I have a question. I tried making a second attack, made a trigger for it, and just copied and pasted your code, but changed the trigger name and the input button, swordattack, and canattack. After I did it, everything seemed to work, but when I pressed the button for the second attack, it worked, but kept repeating with no way to turn it off. Could you please tell me what I messed up?
kind of hard to tell but make sure your animation is not on loop. if you find the animation you can see if its turned to loop or not!
Sorry how do I do that?
@@scubaking4690 well in the video I make an animation and I turn of loop. but you can go on the animation and turn it off
@@ZygerGFX Thank you so much it finally fixed itself. for some reason after I do the animation I have to click the button again to do other animations but that's fine. Thanks again so much!
Can we apply this same to third person view
@17:13 you use "wp" for the "WeaponController" - I miss the part where you change it at random to "wc" - what gives??? like at 18:47, it's "wc" - did you make this tutorial while sitting in the WC?
This was such a good tutorial and i really thought i was able to pull it off, lol nope got error CS1061. i'll still like the video though.
what is the error ?
@@ZygerGFX This is the error code i got. "Assets\WeaponContoller.cs(26,31): error CS1061: 'GameObject' does not contain a definition for 'GetComponet' and no accessible extension method 'GetComponet' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)
@@NotDoubleA you spelt it wrong .. its meant to be GetComponent not GetComponet
@@ZygerGFX oof, i didn't even notice it. thanks for that quick reply
I keep getting this error: InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
Weapon_controller.Update () (at Assets/Weapon_controller.cs:13) Can you help?
you are using the new input system. so you need to either change to the old one. or change the way your checking for input.
@@ZygerGFX How do you change the way. I tried changing to the old one and there were compile errors in the movement.
@@ZygerGFX how do you change the way your checking for input?
really helpful
at 5:25 i did the same things as u did but my sword just keeps swinging
is your animation set to loop ? if so disable that checkbox
i cant get the ¨hit ¨ to show do you know why @Zyger
if i put Debug.log(other.name) in the part whereit is checked with with tag the sword collides i only get the name of my first person controller and i have no idea why
i have these three issues can anyone help with this
error CS0119: 'Component.GetComponent()' is a method, which is not valid in the given context
Assets\collisionDetection.cs(13,31): error CS0103: The name 'wc' does not exist in the current context
Assets\WeaaponController.cs(34,18): error CS0428: Cannot convert method group 'GetComponent' to non-delegate type 'AudioSource'. Did you intend to invoke the method?
Thank you!
very late here. When I attack the first time, canAttack doesn't become true again. It just stays unticked. I double checked code but can't find anything :(
Nevermind. Obviously didn't check code properly. I didn't even start the coroutine haha!
thank you so much
I have a problem, i have an enemy that can move and look around, but hen i give it animations it can't move or look around. any tips to prevent this?
make sure your animations don't alter the position of the object. That will prevent it from moving. So just remove the position changes in the animation :)
its hard zyger i cant do it
Im getting this error after finishing the WeaponController script.
"InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings."
your trying to detect input using the old input system methods while your using the new one. Either change the way your checking for input or revert back to the old input system.
Thank you
thansk for it
11:17
what abt the fps game??
is it canceled?
this is really2 good
Does anyone know why my mouse button isn’t working i set it to input.Getmousebutton(0) but it isn’t doing anything in my game
Make sure to use the old input system. And ensure there are no errors. It should be Input.GetMouseButtonDown(0)
@@ZygerGFX yeah i forgot to type down in my comment 😅 but what do yeah mean by making sure to use the old input system
@@dezhofman3958 well unity has 2 systems the old classic one and the new one so just double check which one your using I project settings. Also debug your code see if the function gets called and if the input is actually detected.
Hi, i recently started coding in unity and I have copied everything from the video, until 10:26, but when I press the button, nothing happens. Do you have any fixes?
Debug your code. Chekc whether functions get called. Whether the input actually gets called and is working. From what you said I cant tell what's wrong but just debug your code and check if things get called
@@ZygerGFX how do I debug the code
@@supernick7773 I recommend researching how to do that. but you should use debug.log to send messages. you can write this in functions and you will receive a message in the console. which will tell you that the function gets called. if you don't see it, then it means it doesn't get called. which means something is causing the function not being called. you can always join the discord server and ask people in the help channel for help ! :))
SECOND BRACKEYS PLAS!
i need 3rd person
Found ya
14:00
cool
6:13
wowo 10 seconds ago
How could I use this to kill an enemy?
well in the video I showed how enemies can detect an attack from the player. in my case I make them play an animation and spawn some particles. but if you want to deal damage do that there. and what you do will depend what sort of health system you have implemented.
@@ZygerGFX Ok, Thank You.
@@ZygerGFX Sorry, one last question what particle did you use?
@@alphakelo dont apologise xD. what do you mean by what particle ? its one I made myself
@@ZygerGFX ohhh ok, (I'm new too unity and Coding thought that particles were a prebuilt thing lol)
im the first like lets go
No you're 2nd
hey friend can you make this video in a new way for 2021...,
ua-cam.com/video/ajzHkYow-so/v-deo.html&ab_channel=DonHaulGameDev-Wabble-UnityTutorials
Nice tutorial, but are you **in hurry** to somewhere? Clicking so quickly through scripts felt nearly criminal.
"As you can see this is extremely basic..."
self esteem: 📉📉📉📉📉📉
I spent the better part of 9 hours trying to figure out why the animation part wasn't working... editing code, placing debugs, looking for boolean code that would work, trying to put the script onto different assets to see if that would work... only to realize that I had accidentally made a bool instead of a trigger.
Don't be a fool, don't be like good ol' Dries over here, make sure to check that your triggers are actually triggers before wasting 9 hours of your life.
Ah that sucks. I'm pretty sure I've done that before too... 😅 at least now you know
you just saved me
For people who have the problem of it not always registering the hit, the problem is that the collider is always active so therefor is always touching the enemy. To fix this first make a public gameobject for your hitbox and then have a HitBox.SetActive(true); for when you attack and a HitBox.SetActive(false); on your reset cooldown
How, pls help
I cannot tell you how valuable this comment is
@trentonbeeson7132 Thanks. Happy that my brief knowledge of coding helped
This was a really good tutorial and I learned a lot, is there any sort of health and damage system that you know of that would work along side this tutorial?
Good question.
yeah - see my post above on similar question - but I'll answer here too. You need of course to have a Enemy Health Controller - a script that controls the Enemy's Health status. you attach it to your Enemy Controller. In that Enemy Health Controller script, you create a public function called DamageEnemy(float damageAmount) which defines how the Enemy takes damage. Usually it's something like: {currentHealth = currentHealth - DamageEnemy} -- sorry but youtube does not like "minus equals" using symbols you know what I mean -
so then, in the Weapon Controller, when the HIT is being done, in the part where you're playing that animation controller - where the SetTrigger ("Hit") is happening - well, you actually made a hit - the enemy flinches with its "Hit" animation and "bleeds" a "Blood particle" that's instantiated. That's where you wanna then take off some Enemy|Health - so here you code something like other.gameObject.GetComponent().DamageEnemy(damage); where "damage" is defined as a float in the WeaponController script -
good luck
ok, so i had this problem where my sword would swing but it was stuck in the attack animation(it wouldnt go back to idle animation). I had to click twice on my mouse btn in order to go back to idle and then i could attack again, so my solution was: Put the Anim.SetTrigger("Attack"); also in the ResetAttackCoolDown() method. That fixed it for me.
Can someone copy the script here becose it didn't work
I found an open sourcish project thats aiming to create a custom launcher for everquest trilogy and its being ported over to unity. I REALLY appreciate the unity videos ive found because i habe NO idea ehat im doing yet and your tutorials are extremely helpful. Youve become a huge part of a dream thats coming true. Thank you.
Really well explained and easy to follow, thanks for making!
How to get Code pls i am big fan :(
Hi, everything worked perfectly but I was just wondering if it is necesary for the object's colliders to be on trigger since when I have them on trigger I can just walk through them. Ty for reading
Aren't animation events better then coroutines in this case? Much easier to control and no timing problems.
yes they are i didnt bother showing those since this is more of a tutorial on getting the basic weapon mechanics. but you're totally right
Now i gotta look up animation events? If i want something to end when animation ends. thats what i need to use?
You did a great job with this tutorial. You are going to have a great career in game dev ahead of you.
this is nice but theres so much extra BS about "you can do it like this or like this or i like to do it like this" which is just too much babble. and overall talking just too fast anyway. i recommend chilling out some. this is too hyper.
love this system, very easy to understand and works great! thanks for sharing
thanks I appreciate it !
I Cant Drag In Da Anims And Make A New Trigger :( (i found out that i didnt select the sword and when i did and then looked in the animations they were there no worries)
i like your channel thanks!
Thank you so much Zyger!
Very cool! 👍
Thank you zyger realy cool tutorial you saved my life
probably the best unity tutorial for fps melee combat ive come across, thank you.
Thank you for this amazing tutorial
Somone how i have 26 errors
Phenomenal.
I'm probably not the first to say this, but it is so nice to hear a girl talk for once in a male-dominated platform, especially in the game development community. Thanks!
Great tutorial! Only thing I'm a little confused on is how to have the enemy lose HP. was think it would make more sense to have the collision be handled by an enemy controller script and access a variable from the weapon called damage then if the OnTriggerEnter for if the enemy touches the swords hitbox to subtract the damage from health
naw, you're gonna have to create in your Enemy Health Controller a function where it takes the damage. Say, DamageEnemy. Then in the WeaponController, you're going to GetComponent
SORRY i used minus equals for code and it did it above as a "strikethrough" currenHealth minus equals damageAmount etc above, not strikethru lol
I got up to the point where I have an attack animation and an enemy that goes into the idle animation, but when I actually attack the enemy, it doesn't do anything like the colliders aren't detecting. I am very confused because I pretty much just copy/pasted everything you did.
hey you might not see this, but i am getting this error where it says "wc does not exist in this context." please help
Mine doesnt show the sword, can attack and attack cool down on weapon holder
K ima watch this after school for my game!
Hi @zyger, i need some help and im hoping you see this as it is my final year project, i would like to know how i can make my AI enemy to not be able to walk through the player or the trees bcs when i activated the isTrigger, he seems to be able to pass through everything
you can have 2 colliders on it. One which is OnTrigger and the other that isn't. You could also write a script that checks the distance between the enemy itself and the player and makes it stop moving when it reaches a certain distance value. Best of luck
thank's a lot:;;;
Thank!
nice
code is so poop
then why did you watch the video?
how to do auto swing every 1 sec when holding mouse0? thanks in advance!
Input.GetMouseButton instead of Input.GetMouseButtonDown will work
How would i have the enemy lose health? I thught that you would go over it but apparently not
when you detect the enemy getting hit just decrease their health like health-=10;
@@ZygerGFX I'm relatively new to coding so if you could elaborate that would be great
@@alsowow well in your code you detect the enemy getting hit so if you followed the video that would be in the enemy script under OnTriggerEnter decrease the enemies health like: health -= amount;
Health, is just a variable that you can set to whatever number you want and amount is either a variable or could just be a number of how much you want to decrease the health by.
Hi, Im pretty new to unity, but I have copied down your script (up till 10:39) and everything seems correct but when I click nothing happens? Can someone please help?
use debug.log to check if the function is being called. if it is then maybe something with the animations. and if not you probs not calling the function or input isnt being detected
@@ZygerGFX Oh my god, thank you so much
Every time I press the attack button, it does not work, what do I do? Is there a way to change the attack button to the space button?
yeah, change the input from left clikc to spacebar
@@quinnncy4703 Could you elaborate?
@@TheJuggernaut. on the part that is like GetInput(mousebutton) change it to spacebar
@Quinnncy You wouldn’t mind elaborating further, would you? Like instead of which line, should I add a correct one?
Great vid, crystal clear and easy to follow , tyvm!
poor