- Home /
I needed to be more specific
A Fighting Games Hit boxes
Animations should always be purely aesthetic, right? Physics are kept to scripts, and animations just make things pretty, that's how Unity seems designed and I can't make it work another way effectively.
But what if instead of just turning a hitbox collider on or scanning infront of the player, you wanted to make Tekken, Dark Souls, or Street Fighter?
How can I make animations that move the root of my character reliably without turning off a characters physics?
Otherwise, how would one go about managing the hitboxes and animations for something where they're complex, specific, and mobile like a fighting game?
Does anyone have any implementations of that have worked for them? How did you do it? Anyone have video tutorials?
Thanks so much, I'm sorry this question is so big and vague.
Answer by CardboardComputers · Aug 13, 2020 at 04:53 AM
Well...
Really, most of it is beside the point. You don't usually want animated hit-boxes or physics engine physics applied to characters in fighting games, but since you're wondering,
Let's talk animations I guess
When you animate a 3D model, usually you use an armature, which basically means you also create the model's skeleton, then attach each vertex to some bone in the skeleton, and then move the skeleton around. The skeleton is basically a tree in which each node describes one bone; this offers some advantages and disadvantages depending on the situation, but makes it easy to process and relatively easy to animate. When you import the model, you can also import the skeleton/armature/rig/pick-your-favorite-name, and when you load the animations into a model in a scene you can see that:
The object for the model actually has the rig in its hierarchy, meaning all the bones of the skeleton are inside it as separate
GameObject
s, each one with its own transformTransforming a bone transforms the model, so adjusting the bones will adjust the model accordingly, meaning Unity keeps the model attached to the skeleton
Playing an animation transforms the bones, which then transforms the model
The important part to realize is that (3.) implies you can attach anything to any bone in order to make it move with the bone. For example, if you wanted to add a shin-guard to a character, you can literally parent the shin-guard's GameObject
to the shin bone in his skeleton, and the shin-guard will follow whatever changes happen to his leg (in terms of linear transforms: moving, rotating, and scaling). When he kicks or runs, the shin guard stays attached to this leg bone. Unity even provides special cases for armatures that look humanoid enough in terms of bone structure.
Notice that this means you can add a Collider
to a bone so that it follows all the motions of that bone. There's no reason you can't use an animation for collisions.
Unity supports this thing called root motion; I'm not sure if that's what you're looking for in terms of "animations that move the root [...] reliably".
Physics?
When it comes to physics, usually you don't want characters to act within the physics engine. This will expose them to all sorts of whimsical things like sliding down hills and rolling around and bouncing when you hit walls. This is especially true with your animated Collider
hit-boxes: if anything else, at least use a separate, non-wiggly collider for interacting with the world. Otherwise, every time your character turns or animates, he'll punch through the floor or a wall and jitter, get stuck, or go flying.
If you really need to apply physics to a character, it's generally best to do it in a script so you have fine control over exactly what can or can't happen to a character.
Fighting game implementations
Honestly, I can't say for sure, because I don't know how your examples are made, but it's important to keep in mind that Dark Souls is significantly different from Tekken and Street Fighter. Dark Souls plausibly uses animated hit-boxes to keep track of different body parts getting hit, but I don't think either of the other two really need that information. Instead, for simplicity and performance, especially for earlier releases, I'd imagine they just check a (2D) rectangle or (3D) capsule. The game doesn't really care what body part you hit, and doesn't need to be that precise when everyone's jumping 5 metres high, firing lasers, shooting this or that fancy grab, and casually punching through asphalt.
I'm sure there are better researched answers especially with regards to the specifics of the games; you're welcome to look online for things like that in blog posts etc.; they can't be that hard to find. Same goes for any video tutorials, just wander around online and you'll find quite a few about animations, physics, and hit-boxes for Unity. As always, try to keep your questions specific, and while it is nice to interact with people, try to use "Ask a question" as a last resort—unless you can't find any videos, articles, or examples by yourself, try to avoid asking for them here. That being said, don't be discouraged if you can't find anything; if nothing else, it'll help you form a more specific question, and might help you better understand how a solution works when you find one.
Thanks, I think you're right.
Hearing the different ways games tend to implement this sort of thing was helpful and was what I was looking for, but you asked about my specific implementation problems and I don't think this post was specific enough.
I'm making a 3D game with 2D sprites, so there aren't armatures. Attacks are mobile, so there's animations on the characters transform. I was running into all sorts of problems with root motion and I think I could've focused down on one of those-- but I decided to restart my game from scratch recently and wanted to get ahead of the problem by asking about it, that's why it's so vague.
But I have an idea I'm going to try-- animation controller on a parent which controls various children and root motion, and scripts that are written to play and stop animations based on collisions and what not. I'll try posting again if I run into a specific problem. I'm ok for right now.
Follow this Question
Related Questions
Hitting Multiple Enemies 1 Answer
Weapon attack 0 Answers
noob question about melee combat 1 Answer
Hit detection for Fighting Games? 1 Answer
Drawing Rectangles in 2D for hitboxes: fighting game 1 Answer