- Home /
Disable transform inheritance for rigidbody
By default in Unity3d transforms that have attached rigidbody still inherit position and rotation changes from parent. Is there a way to somehow disable this behaviour, other than breaking the hierarchy?
Here is an example when this inheritance movement is unwanted:
I have a ragdoll on my character, and the character holds weapons in his hands, that have free moving parts. I have animation for the character, and thus for the main part of the character body isKinematic is turned on, but I want the weapons movement to be modelled. The inheritance deprives the poor weapon of its inertia, making it follow the hand. But breaking the inheritance will also cause me problems, as sometimes I want to manually set local transform for the weapon.
A bit lagging video example. The weapon sure behaves badly.
Pretty obvious workaround is making the "clones" of the weapon outside the hierarchy, and than copying their global coordinates on the actual weapon objects, but the situation seems rather standard and so it seems there might be a better solution to it.
Answer by Adam-Mechtley · Dec 09, 2016 at 06:48 PM
Hi @sadenly. A related topic actually just arose internally today. If you're wanting the handle the character is holding to be animated, and only the dangling part to be physical, you should be able to simply unparent the physical parts when the game starts. Physics are ultimately calculated in world space anyway, so your joint's definition at creation time (i.e. when the game starts) will not be affected by your transform topology.
Hi @Adam-$$anonymous$$echtley! Thank you for your reply!
Well, the problem with breaking inheritance is that actually we have animations that contain information for (animate) the dangling weapon part, but we also have many animations that do not contain the weapon transforms, when playing later we want the dangling parts to be controlled by physics, when former - by us.
If we break inheritance, switching from animation "with animated weapon" to animation "without animated weapon" and vice versa will become more complicated, we will have to change each time from one hierarchy to another.
Do you think it will be more profitable than having "clones" or maybe there is some other way of handling this?
I am actually really interested, maybe there is some way to handle this in mecanim?
So what you need is a way to transition smoothly between animation control and physics control. Unfortunately this is a thing that is not (yet) possible with built-in tools.
Currently, what you need to do is have some non-rendered bit of the hierarchy that is controlled by animation and a separate physical hierarchy (usually flattened) that tracks the animated transforms (kinematically or actuated) with variable strength. I have an Asset Store package, Ragdoll Workshop, which has facilities for this (see this video or others here). There is also a similar product, Puppet $$anonymous$$aster, which I believe provides similar functionality, but I haven't used it personally.
Thanks, yeah, this is actually what I meant by clones - a system, that connects animated and physic controlled skeleton and merges their movement together. Only I thought about doing it the other way around - copying the physics-controlled animation onto the main, animation-controlled skeleton. Actually, I see the benefits of copying it the way you said, as it is necessary to copy from animation to physic controlled skeleton anyway, and you can save the resources of copying back from it.
Watched the video about the package - it looks really awesome! The fact, that it adds the ragdoll simulation as an animation is really intuitive and looks very easy to control.
I didn't quite understand thought if I can turn on physics only for the part of the skeleton and leave the other parts animated? Will it possible with the Ragdoll Workshop?
Thanks for answering, I must have missed it in the video, everything seems clear now!
(For some reason I can't reply to your last comment, so I post as a comment to your original answer.)
Your answer
Follow this Question
Related Questions
Throwing a ball around 2 Answers
How to properly move a rigidbody/collider? 2 Answers
C# always move an object forward and still use physics 1 Answer
Transform.Position vs Rigidbody.Position 1 Answer
how do i make this lag less? 1 Answer