• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by DerDot · Apr 04, 2016 at 06:56 AM · animationragdolltransition

From animation to ragdoll and back

Hello everyone,

following this tutorial I have an animated model that can turn into a ragdoll by setting isKinematic to false on all "bones" and disabling the animation. This works pretty much as intended. While in ragdoll state I apply some force to it, so that it moves away from its original position.

Now I want to switch back to the animated model. But if I just set isKinematic = true and reenable the animator, the model is "teleported" to its original position instead of standing where the ragdoll ended up lying.

I already tried to assign the animator to an empty object of which the model is a child instead of applying the animator on the model directly, but this doesn't change anything.


Edit:

I experimented a bit more. Even saving the new positions and applying them after turning on the animation does not help. The "bones" all lose their newly assigned position after the update call.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by jacupiri · Sep 01, 2016 at 08:35 AM

DerDot, I found the answer for the same problem in the following link:

http://perttuh.blogspot.com.br/2013/10/unity-mecanim-and-ragdolls.html

It works just fine!

The only issue is with GameObjects that are child to your humanoid.

In my case, my character holds a sword, and falls to the ground still grasping it. But when he gets up (using any of both animations), the sword is out of his hand. It's still a child of the hand, but it is offset. And, I don't know why, the sword's collider is no longer a trigger.

By the way, Perrttu, your script is awesome! Congratulations! And thank you for sharing it!

I just would really like to know how to solve this small problem.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jacupiri · Sep 01, 2016 at 12:52 AM 0
Share

There is a solution pack for download in the link above.

avatar image jacupiri · Sep 01, 2016 at 07:49 PM 0
Share

DerDot, I found the whole solution for the ChildGameObjects. A guy called Wilian Silva pointed this out, at Perrttu's blog:

i found a solution just yesterday! Lets talk about the facts: this script recognizes every transform in the ragdoll as a bone, so you don't want your sword to be recognized as a bone. To fix that, you need to ignore all the transforms that are'nt a bone. This is what i did, i went to the Start function and made some changes:

I put a tag named "Bone" to every bone i wanted to do the transition, and this method checks if the transform has this tag, and then if it does, it adds this transform to the components.

_components = GetComponentsInChildren(typeof(Transform)); components = new Component[_components.Length];

for (int i = 0; i < _components.Length; i++) { if (_components[i].tag == "Bone") { components[i] = _components[i]; } }

Sorry for my bad english, and i hope it helps you! :D

avatar image jacupiri · Sep 01, 2016 at 07:51 PM 0
Share

I simplified Wilian's solution:

ins$$anonymous$$d of needing to tag all bones, I just put the condition of having a rigidbody (wich all ragdoll parts have). The Start() function of the "RagdollHelper" script (wich is the core of Perrttu's pack) ended up like this:

 void Start ()
 {
 //Set all RigidBodies to kinematic so that they can be controlled with $$anonymous$$ecanim
 //and there will be no glitches when transitioning to a ragdoll
 set$$anonymous$$inematic(true);
 
 //Find all the transforms in the character, assu$$anonymous$$g that this script is attached to the root
 Component[] components=GetComponentsInChildren(typeof(Transform));
 
 //For each of the transforms, create a BodyPart instance and store the transform 
 foreach (Component c in components)
 {
 if (c.GetComponent<Rigidbody> () != null) 
 {
 BodyPart bodyPart = new BodyPart ();
 bodyPart.transform = c as Transform;
 bodyParts.Add (bodyPart);
 }
 }
 
 //Store the Animator component
 anim=GetComponent();
 }
avatar image DerDot · Sep 13, 2016 at 07:46 PM 0
Share

Thanks @jacupiri this sounds amazing! Sadly I won't have access to a PC for the next 3 to 5 weeks. I'll check it as soon as I can and will let you know.

avatar image DerDot · Oct 07, 2016 at 03:06 PM 0
Share

Works exactly the way I want it, thanks a lot for the link!

avatar image
0

Answer by The-Arc-Games · Jun 29, 2016 at 11:34 AM

There is basically just one solution to this need: dynamically create an animation/ animation state that your model uses to transition from the ragdoll position to the target animation position. You basically use the ragdoll rest position as the starting keyframe of a per-bone animation that has your desired length of time, and targets a last keyframe which corresponds with the first frame of your target animation (i.e. get up).

Achieving this involves considerable knowledge of the technicalities of animations and mecanim, but it requires relatively few steps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ragdoll recover 5 Answers

problem with 2d ragdoll to animation 0 Answers

Transition Between Regular Animations and Ragdoll Physics 3 Answers

How to stop mesh disappearing during Animator state transition blend time? 1 Answer

Mecanim transition condition can't have both bool and trigger? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges