I would like to set an animated mesh of a character (boned, skinned) as a collider mesh.
How can I do this?
As far as I know the SkinnedMeshRenderer sends the modified / animated geometry mesh to its MeshFilter.
So this is where I could get the mesh from.
But how can I get the MeshFilter, where is it stored??
When a GameObject has a SkinnedMeshRenderer it also definately has a MeshFilter, right?
When I call gameObject.GetComponentsInChildren(typeof(MeshFilter));
on a GameObject that has a SkinnedMeshRenderer should I not consequently also find at least one MeshFilter then?
(I have assumed that the SkinnedMeshRenderer is a child of the GameObject and the MeshFilter a child of the SkinnedMeshRenderer)
Because this isnt the case (result is null).
SkinnedMeshRenderers don’t use MeshFilters, they just have a shared mesh assigned directly to them. As far as I can tell (and believe me, I would have loved it myself if I could) you can’t really get direct access to the modified/animated geometry that the SkinnedMeshRenderer calculates for the mesh. So if you want that data, you basically have to implement your own skeleton sub-surface deformation algorithm. And, unless you’re a much better coder than I am, it probably won’t be quick enough to run in real-time. :lol:
Mesh colliders aren’t really great for anything but static objects anyway, though. The main difficulty is that they don’t tend to work very reliably with other mesh/terrain colliders.
The preferred way to set up colliders for a character is generally to create primitive colliders for each of the different parts of the armature, or at least as many as you need for whatever you’re doing. (Like a sphere or a box for the head, one for the chest, and so on) It won’t fit as close to the mesh as a mesh collider would, but it’ll be much faster for the physics engine and more reliable as well.
An animated mesh collider would be too slow to run in real-time, even if it was possible to access the skinned mesh on the graphics card (which it’s not ).
–Eric
Just try to keep down on the animations that extend or shrink pieces of the body. The box colliders won’t update to match the stretches, so you’ll end up with gaps or overlaps in the body’s colliders.
With one collider per bone, though, you can get pretty good body coverage. It even gives the advantage of being able to do limb-specific damage.
I second Gargeraths suggestion.
Thats how it is done commonly as well.
Capsule and ellipsoid are very efficient and basically allow you to approximate any geometrical structure.
Ok, I see.
Maybe I ll have some further questions later on.
For now: thanks a lot for the many replies and information.