How do you go about making a meelee weapon tha damages everyone in the swing do you set it so whatever human it touches? I meen would I need to have a on state for damageing that turns on and off when I start and after a swing so that once you do the full swing it doesnt do alot more tiny dmgs by just lowering back to just idle position?
- You can attach a trigger collider to the weapon, and use that to call your damage function.
- This belongs in scripting, not gossip.
well this is not gossip forum, its unity support if it hasen’t been moved
Like Goonie says its a trigger that you attach to sword I would guess. Have not tried it myself yet but I would probably set enemies to flags and have a OnKeyUp function to turn it on. So when you press a button and release, the objects with flag “enemy” takes a hit during that animation
Hmm, if I may contribute to this discussion…
In my experience it works much better for a game if you can make your melee attack have a larger effect beyond just what the actual model connects with. (Unless you have a motion game that exactly tracks your swing.) Otherwise you have basically this one small area that the attack actually passes through. It can quickly become frustrating to the player as the attack just barely misses the target, and in order to play the game the player needs to exactly memorize the animation and judge its position in 3D space through a 2D interface. Not that fun.
It works much better to actually extend the attack’s reach somehow. How exactly depends on the motion and style of game. For example, if you have standard action-platformer and the character swings a horizontal slice, you’d want to extend that damage area up and down a little. Otherwise, what if you are attacking a small enemy and are standing on a slope? You’d be boned. Or what if it were a straight vertical slice? Your player could directly face an opponent but just narrowly his him because he’s slightly standing to the left and the player is right handed. An opponent with a little bit of bounce in his step becomes very frustrating to fight, and if the camera is not directly behind the player, then you can’t even see how you are missing. But extending the collision of the sword to the sides a bit would help clear that right up. And you might think you can solve both of these problems with a diagonal slice, but you still have the same problem. The diagonal slice makes the player think they have a broad never-miss stroke, but a target that is slightly short and a little off to the side gets missed. A target that is moderately short and almost in the middle gets missed. Very frustrating. You can play with making the slice more shallow or more steep, but in the end you still face the same problems.
It makes more sense to suffer the possibility of it looking a little odd because it didn’t quite hit the target than to have the player be virtually incapable of hitting the target. (Additionally, if you add some flashes or sparks or something like that, it masks these near-hits very well, as well as communicating to the player that the hit was successful. It’s how Zelda does it.)
Now, you might think that the best solution is then to simply enlarge the collision of the weapon so that however you swing it the collision is padded. This idea is flawed. Think for a moment of the very end of the stroke. You have this much larger box sticking out way past what should conceivably be hit by the attack. Also, what if the weapon needs to respond to getting hit, like if an enemy hits the player’s weapon (but not the player) and is supposed to have the attack deflected back? The weapon’s collision is now responding awkwardly to that situation. And of course if an enemy hits the enlarged collision of this weapon and the player takes damage, well that’s just bunk. And if the enemy’s attack just passes through the weapon, it looks odd.
I’m not going to say that I have a perfect solution, but I do have a couple good ideas. the first thing that comes to my mind is that when the player attacks he generates a special object (invisible) with a custom-shaped collision hull to match the exact shape that the attack should effect: for example, a diagonal diamond shape that is pointed at the start and end of the stroke and broad in the middle. Of course this is only useful if the attack is very quick; striking the whole area within one or two frames. Otherwise enemies get hit by the end of the strike before it hits them. My next thought is to have a collision hull that is animated. While it remains unseen to the player, the a shell is mounted to the weapon (or is simply part of the player model) which is designed to extend/contract according to the animation. That way it could be smaller at the start and end, extend to a larger size where it needs to effect a larger area, stretch in single dimensions according to the specific blow being made, and stay with the animation so objects don’t get hit until they would look like they get hit. I would also suggest adding a “tail” to the dynamic collision animation so if the swing is just a little early it still hits.
Of course, I am new to Unity and cannot claim I know how to perform either of those techniques, but I am curious what others think, or if they have more practical solutions.