- Home /
What is the best way to script third person real-time action melee combat in C#?
So for our game we want to have third person, real-time, action melee combat, using a sword, with a crosshair. What would be the best way to script this?
A collider on the end of the sword maybe? Or a raycast/spherecast?
Game examples with this combat system would be: Darkfall Online, Risk Your Life, TERA Online, etc etc.
Answer by superpig · May 07, 2011 at 09:16 PM
It depends on how precise you want your swordplay to be. If precision control of the sword is part of the game's design, then you definitely want a collider on the sword.
However, if your melee attacks are more simple than that, and are more 'point and shoot,' then I'd probably use Physics.OverlapSphere() or Physics.SphereCast() in the 'hittable region' just in front of the player. Use an animation event at the right place within the melee animation to trigger the actual check and knockback.
Also, are there any other options I'm not considering? And which would be more multiplayer friendly?
And, which do you think big game developers use for this type of combat? Haha.
Attaching a collider to the sword is probably easier.
There's one other option I can think of that I didn't mention, which is to create a sphere collider game object that is actually a child of the player and moves with them, flagged as a trigger; then have a script on that collider that tracks objects entering/exiting the trigger. That way, ins$$anonymous$$d of having to check for objects in front of you, you'll get notified about them by Unity.
In my game I'm using a mixture of these techniques; to my knowledge, there is no one single best option (or I would have told you so already).