- Home /
How should i properly do sword combat? (Think: M&B/Oblivion/Skyrim)
I'm talking about a 3DP/FPS game here, which means you will be aiming your swings.
If you guys have ever played any of the Mount & Blade games you'd know how it works, basically you can choose to swing your weapon, lets say it's a normal one handed sword that we are using, from 4 different angles: Left swing, right swing, overhead swing and a stab. The same goes with blocking with weapons (unless you have a shield, which will block the area...well, where the shield is).
Now, i've asked a few people and they have told me to check collission with the weapon and the enemy that i happen to hit, and have the sword be a child to an animated model. I find animating time consuming and i prefer to do programming, and not to forget my animations look like hell.
You guys think i should do is this way, or try to fake it all with raycasts all over the place (depening from which angle you swing)? I'm not against doing animations, it is fun, but like i said pretty time consuming, and i wouldn't want to waste time doing something "the wrong way".
I'd love to hear how you guys would make it work/how games like those mentioned make them work.
Answer by RyanZimmerman87 · Feb 09, 2013 at 03:57 PM
I am not sure how you intend to do all these different kinds of sword attacks without any animations? Without animations you won't be able to see the different sword attacks so it kind of defeats the purpose?
My advice is to bite the bullet and learn at least basic animation. I think the simplest way to do this is to use Animation Events (a built in Unity feature!). Meaning you create an animation for your character (I prefer to do this in Blender since it's free and no royalties), once you have the animation you can select your desired frame within the animations progression and create an Animation Event.
You can create a function in your characters script for example "void playerAttackEvent()". You can then very easily call this function with your desired animation frame timing. Here is a great tutorial which explains how to do this perfectly:
http://www.youtube.com/watch?v=QNdGBBsC9_I
What are you using for your character right now? I am having trouble imagining your set up without any animations. But don't worry I was there myself not too long ago. After learning how to do Animation Events I can't imagine any simpler solution to this problem. You don't even necessarily have to detect your swords collision on the enemy (depending how realistic you want the game to be). You could simply have a "if" statement within your "void playerAttackEvent()" which only does damage if the enemy is within a certain distance.
You should create a different animation for each of your desired attacks, and call different functions from your characters script for your desired affect. I believe this a nice way to solve your problem.
Here are two more videos which helped me learn how to Animate a character in Blender:
Rigging and Skinning Character: http://www.youtube.com/watch?v=PPbSGUPj72w
Simple Walk Animation to get you started: http://www.youtube.com/watch?v=kSDWfx6ib9k
I think I may make my own tutorials pretty soon once I become a little better with this stuff. Honestly it was really hard to find good comprehensive guides on how to do the most simple things a game maker needs.
People always assume you know how to do things when really they could teach someone who knows nothing how to do it if they are good enough at explaining the process. Good luck hope this helps!
Oh no, ofcourse i'm going to use animations. :)
Obviously you got confused but what i meant was: should i check for colissions between objects; in short, letting animations take control of what i hit, or deter$$anonymous$$e if my enemies got hit by some other kind of method, like raycasting?
Anyways i already went and made some animations the day after asking this question, and made a script that checks for collissions with the weapon in question and any given enemy, it works semi-okay for what i want it to do now. I guess coupled with some short raycasts & multiple "hit boxes" per sword could make this work for accurate damaging.
Even before asking i knew how to make something like this, i'm just asking for pointers/advice on how to do it properly, concidering i'm drawing alot of attention from games like $$anonymous$$&B and Chivalry (and the numerous Source H&Ss), and thus want it to be as humanly accurate as possible.
I'll go with my "multiple hitbox-raycast" thing and see how it works out, and how accurate & playable it is.
Answer by Ecofox · Feb 09, 2013 at 01:29 PM
Well I read this and it might be helpful. http://answers.unity3d.com/questions/296900/swinging-a-sword-through-code.html
But that might be too basic. As for the sword swings Mount and blade > Zelda > Oblivion.
well oblivion is not a swing at all.
it's actually just trigger.
but animations makes you feel like it's a swing but it's not.
Answer by TheEpicWhiteFox · Dec 20, 2013 at 04:52 PM
How I would go around this is by using both solutions. Animation cannot be avoided nor can collision detection when it comes to realism.
First of all, you should make an animation for each of your swing directions and types; converting them all to animation events.
Next,you detect player input of "melee" then set a state of "damage inflict" on the blade which detects collisions between the blade and the target, causing damage on contact (and momentum if you'd like).
Then, use Unity's Locomotion system (which comes with a tutorial on how to set it up http://unity3d.com/support/resources/unity-extensions/locomotion-ik)to influence the swing's direction towards the target.
Afterwards, after the swing takes place, remember to disable "damage inflict" and to end the combo/swing.
Your answer
Follow this Question
Related Questions
How should i make sword combat ? 1 Answer
Inverse Kinematics for Sword 0 Answers
First person hack and slash weapon. 0 Answers
Best way to detect sword hit 0 Answers