The game I am developing has equip slots for clothing. I am handling this by replacing the armor models bones with the players bones at runtime when a piece of armor is equipped. This works fine for majority of the armor. It shows up correctly, moves with the players animation, etc. For one side of the leg though, the leg armor clips through the players leg. The animator swears up and down that it is skinned correctly, that it isn’t an animation or model problem. Given that it works fine for all the other armor pieces, I don’t believe it to be an engineering issue. Could anyone shed some light on possible causes of this?
It could be the animator and the engineer are both correct.
Is the armor clipping because the armor piece is not in the proper location/orientation - instead of a zfighting issue?
Maybe the pivot point of the armor piece is offset slightly in the authoring tool - causing the code to place the armor piece in engine incorrectly.
Seems this wouldn’t cause problems since the armor pieces are skinned to bones - so the parent bones pivot would control where the armor piece is placed in engine.
Could this be a result of a mirrored bone in the authoring software?
Really just guessing.
When you say:
“replacing the armor models bones with the players bones at runtime when a piece of armor is equipped.”
Do you mean “replacing” or do you mean matching? Obviously the character’s skin is still there so I think you mean matching. This is important because it is the difference between two skeletons on the model or one.
So please clarify that, but there are a few things that may be causing this. First is that if there are two sets of skeletons one may not be perfectly aligned with the other. You could easily trouble shoot this by just selecting corresponding joints during playtesting and insuring that they have the same transforms.
If they do match up then you probably do have a skinning issue. Unity optimizes skin weights. You may think that the skin weights are solid, but they may have very small amounts of weight assigned to the wrong joint that when optimized in Unity can create this issue. To insure that the skin weights are done correctly insure that all of your model’s smooth binds have a max influence of 4 (the max for unity). Now in Maya there is an editor called the component editor where you can view actual numerical values for skin weights by selecting the vertices. I’m sure there will be such and editor in your package whatever that may be. But select the vertices that are off and insure that there is absolutely no weight on any joints you don’t want in the mix for that vertex. Even a very small amount of weight can trigger an optimization that selects the wrong joint for the redistribution.
Finally, and take this for what you will, but in my opinion this is not the best way to do this. I have tried to do something similar and it is both taxing for the frame rate and loaded with these sorts of alignment issues. The better solution is to model the mesh with the armor or in my case clothing in the same mesh as the character’s skin and rather than having the skeletons layered on top of one another swap out the skinned mesh instead.
In Max this is the weight table, though suggest using the weight tool instead - personal preference.
How I am doing it currently is that I replace the clothes SkinnedMeshRenderer.bones array with a new array of the player characters bones. I passed your comments about the weights on to the modeler, thanks. I’m not sure how your suggestion of swapping the skin would work? Do you replace the entire set of armor for the character? We are doing a slot based equip system, so you can have different pants with different shirts with different gloves, and so on.
While I’m not quite sure of the exact source of your problem, you might find inspiration for a solution here. The author is taking a similar approach to outfitting the characters in his game, and the plugin he offers reflects his solution to the poke through problem.
So if you have a mix and match sort of system swapping out the mesh wouldn’t work because you would have to model every possible combination. So never mind on that. That ootii system that hopeful proposed looks really good. Seems like it may be a bit heavy on the computation, but if you can afford the bandwidth that looks pretty sweet.
This is also a related thread that should be helpful