So overview of my system:
Bear in mind, that I'm not programmer so some of my code might look really stupid and unefficient.
I've separated every limb in blender to make my work easier in Unity.
I've also parented every mesh same way rig is parented.
This way Unity will automatically make mesh hierarchy same as rig hierarchy. This is not mandatory but just makes things easier in Unity.
I'm using Puppetmaster to control character physics and FinalIK for Full Body IK movement which I use to control both hands.
Every breakable skinnedMesh has reference to of all of it's child skinnedMeshes which is called MyLimbs.
Every limb in Puppetmaster ragdoll has a reference to same skinnedMesh limb.
When ragdoll limbs gets too damaged it will break and call method BakeLimbs() from it's skinnedMesh counter part.
SkinnedMesh will then make new temporary GameObject, change position of this empty gameObject same as it is in Ragdoll limb and bake current vertex positions of skinnedMesh to a new gameobject and copy skinnedMesh materials.
Bakedmesh will copy rigidbody from puppetmaster and use reflection to copy whole ConfigurableJoint component from puppetmaster ragdoll to bakedMesh with one change,
ConfigurableJoint.connectedBody changed to correct parent.
Items are parented to Puppetmaster ragdoll so I need to check what is current item and change it's FixedJoint.connectedBody to bakedmesh hand gameobject.
Then I apply same velocities as it's on Puppetmaster Ragdoll so the dismembered limb will break naturally instead of just dropping off.
I had quite alot problems with adding collider with correct orientation so I add collider as a child of this new bakedMesh. This new collider copies properties from Puppetmaster ragdoll, and changes layer to correct one. (I did not know about reflection when I was doing collider part but ofc I could use it also here just like with ConfigurableJoint)
And finally disable old skinned mesh renderer.
It was much more work than I first thought but that is how game development always goes :-)
Here is my current codes, quite un-commented but I hope these are clear enough. Leave a comment if you have any questions!
First the code which is on every detachable skinnedmesh
Second code is on every breakable Puppetmaster ragdoll limb which can break.
Third is both Bone and Item components.
Every limb in Puppetmaster ragdoll has a reference to same skinnedMesh limb.
When ragdoll limbs gets too damaged it will break and call method BakeLimbs() from it's skinnedMesh counter part.
SkinnedMesh will then make new temporary GameObject, change position of this empty gameObject same as it is in Ragdoll limb and bake current vertex positions of skinnedMesh to a new gameobject and copy skinnedMesh materials.
Bakedmesh will copy rigidbody from puppetmaster and use reflection to copy whole ConfigurableJoint component from puppetmaster ragdoll to bakedMesh with one change,
ConfigurableJoint.connectedBody changed to correct parent.
Items are parented to Puppetmaster ragdoll so I need to check what is current item and change it's FixedJoint.connectedBody to bakedmesh hand gameobject.
Then I apply same velocities as it's on Puppetmaster Ragdoll so the dismembered limb will break naturally instead of just dropping off.
I had quite alot problems with adding collider with correct orientation so I add collider as a child of this new bakedMesh. This new collider copies properties from Puppetmaster ragdoll, and changes layer to correct one. (I did not know about reflection when I was doing collider part but ofc I could use it also here just like with ConfigurableJoint)
And finally disable old skinned mesh renderer.
It was much more work than I first thought but that is how game development always goes :-)
Here is my current codes, quite un-commented but I hope these are clear enough. Leave a comment if you have any questions!
First the code which is on every detachable skinnedmesh
Second code is on every breakable Puppetmaster ragdoll limb which can break.
Third is both Bone and Item components.
Ei kommentteja:
Lähetä kommentti