I think I did something similar once, forgot, watched it in rewind mode for 5 minutes and remembered everything, thank you!
@SunnyValleyStudio11 ай бұрын
Awesome! Thanks for the comment 🙂
@zapleaf2 жыл бұрын
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!
@SunnyValleyStudio2 жыл бұрын
Thanks!
@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 Жыл бұрын
Thanks for watching! 🙂
@looeehg249015 күн бұрын
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 Жыл бұрын
Great tutorial! Thanks for this!
@SunnyValleyStudio Жыл бұрын
Glad it was helpful! Thanks for watching! 🙂
@brandonjacksoon2 жыл бұрын
Thank you mister! You have a really helpful tutorials!!!
@ProgressshGames Жыл бұрын
Very helpful video, thanks!
@SunnyValleyStudio Жыл бұрын
Thanks for watching! 👍
@김익환-o4m2 ай бұрын
Best video.!! When the character moves up or down, the weapon shakes. Why is that? :(
@SunnyValleyStudio2 ай бұрын
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.
@lukemarkbrady6 ай бұрын
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?
@SunnyValleyStudio6 ай бұрын
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 🙂
@amritsahani694202 жыл бұрын
It helped a lot never give up💪
@brandonjacksoon2 жыл бұрын
Best of the best ;)
@luxe10984 ай бұрын
after i attack the weapon stops following my mouse movement, why is that?
@SunnyValleyStudio4 ай бұрын
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!
@ggnouhiiam4 ай бұрын
the delay is not really working, i can still spam my attacks even though it's running through the coroutine
@SunnyValleyStudio4 ай бұрын
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?
@ggnouhiiam4 ай бұрын
if im correct then you can set the delay to any amount and you can still spam it
@SunnyValleyStudio4 ай бұрын
@@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.
@ggnouhiiam4 ай бұрын
yeah i figured it out when i saw the block attack
@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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@SunnyValleyStudio Ok, I joined
@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 Жыл бұрын
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Ай бұрын
does this process work in bow?
@SunnyValleyStudio29 күн бұрын
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 Жыл бұрын
Does this work for side scrollers like something like hollow knight?
@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
@chunlam72832 жыл бұрын
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.
@SunnyValleyStudio2 жыл бұрын
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 Жыл бұрын
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
@carlabalos38842 жыл бұрын
Could you do a combo attack for this one too like one slash after another? Would really be helpful.
@SunnyValleyStudio2 жыл бұрын
I will see what I can do. First I want to tackle context steering ai
@carlabalos38842 жыл бұрын
@@SunnyValleyStudio Thanks
@durrium2 жыл бұрын
Somehow there is no posibility to drag in the sprite into the animation window. Strange!
@durrium2 жыл бұрын
EDIT: Had to choose the gameobject in the hirearchy to add sprites!
@SunnyValleyStudio2 жыл бұрын
I'm glad that you have been able to figure it out!
@Al-Asire Жыл бұрын
I need the code to download it if you can thank you
@SunnyValleyStudio Жыл бұрын
Here are the scripts github.com/SunnyValleyStudio/Melee-combat-system-Unity-2D
@henrysharingan2 жыл бұрын
What about combos?
@SunnyValleyStudio2 жыл бұрын
I am just working on a project with combos! Maybe I will be able to create a tutorial about it :) Thanks for a suggestion!
@n0n3x2 жыл бұрын
Does this work for 3D?
@SunnyValleyStudio2 жыл бұрын
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.