Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Dr_GeoFry · Mar 17, 2013 at 11:09 PM · animationragdolltransitions

Transition Between Regular Animations and Ragdoll Physics

Hi everybody,

I know how to create animations, and I know how to set up rag doll physics on a character. My main question is how do I write a code that ends regular animations (walking, running, fighting etc.) upon dying, and transitions into a rag doll effect on death.

Alternatively, I'd like to assign certain health to certain body part, and have it respond to rag doll physics without requiring the character to die. In other words, if the character gets shot in the head, I want his head to swing back, and snap back into place. Similarly, I would like that to happen to shoulders, arms, chest, and legs.

Thanks for your help

Comment
Add comment · Show 1
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 Benproductions1 · Mar 19, 2013 at 12:23 AM 0
Share

The certain body parts moving independently on hit should be done with animations, while the ragdoll (I'm assu$$anonymous$$g you have it set up) can be done by disabling the rigidbodys when player is alive and enabling them on death.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Benproductions1 · Mar 21, 2013 at 11:26 PM

Hello again,

If you want to disable all rigidbody's, you can simple do:

 function DisableRagdoll() {
     var rb:Rigidbody;
     for (rb in GetComponentsInChildren(Rigidbody)) {
         rb.enabled = false;
     }
 }

To enable it, just replace rb.enabled = false; with rb.enabled =true;

Hope this helps, Benproductions1

Comment
Add comment · Show 7 · 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 Benproductions1 · Mar 22, 2013 at 12:17 AM 0
Share

I don't understand what this should do? Do you want this to happen when he dies, in which case it should be hitPoints < 0 or do you want this to happen while he's not dead? In which case Destroy makes no sense what do ever

avatar image Dr_GeoFry · Mar 22, 2013 at 12:27 AM 0
Share

@Benproductions1 this is just a test. I don't want to go through the trouble of injuring the enemy, so I make the conditions for this to trigger happen as soon as the program begins. As of now, all that happens is that the enemy is destroyed. If I wrote the script correctly, it would look like yours, but I'm using a short cut.

avatar image Benproductions1 · Mar 22, 2013 at 01:12 AM 0
Share

@Dr_GeoFry So what does this code accomplish? It freezes all rigidbodys in the rigidbodys list and destroys said rigidbody in 3 seconds, then destroys the gameObject that the script is attached to in 12 seconds. then it makes a variable called enabled equal to false. I can't tell you where you went wrong, before I know what it's supposed to do! :P

avatar image Dr_GeoFry · Mar 22, 2013 at 02:33 AM 0
Share

lol, @Benproductions1 I was throwing all kinds of variables at this hoping to get the code to destroy all of the rigidbodies. $$anonymous$$y goal with this code was to have the animation play for X amount of time, then destroy the rigidbodies, and then remove the enemy altogether. I thought that I needed to either destroy or disable rigidbodies or disable is$$anonymous$$inematic in order to make the ragdoll effect happen. That, or make is$$anonymous$$inematic equal false. It seemed like this transition should be easy, but for some reason, I'm missing some part of this that is critical. Thank you for your help.

avatar image Benproductions1 · Mar 22, 2013 at 04:24 AM 0
Share

For the ragdoll effect, you need to enable the rigidbodys, not destroy them! Therefore is$$anonymous$$inematic has to be false and/or enable the component. Also you should use {} to wrap code:

 for (something in somethings) {
     //Do something
 }

Never try and throw code together, it won't work 99.9999% of the time. Focus, gather your thoughts and think what should happen and how do you achieve this.

Show more comments
avatar image
1

Answer by Kavorka · Feb 02, 2014 at 08:03 PM

If this is what you want:

"Alternatively, I'd like to assign certain health to certain body part, and have it respond to rag doll physics without requiring the character to die. In other words, if the character gets shot in the head, I want his head to swing back, and snap back into place. Similarly, I would like that to happen to shoulders, arms, chest, and legs."

you should look at this AnimFollow.

AnimFollow makes a ragdoll follow an animation with some strength and lets you lower the strength for individual body parts so that they may be affected by physics. Then lerp the strength back to make it follow the animation again.

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
avatar image
1

Answer by lelis718 · Nov 02, 2015 at 02:45 PM

Maybe this is what you are looking for

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

Comment
Add comment · Show 1 · 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 NathanJSmith · Jul 02, 2018 at 05:01 AM 0
Share

[+1] Thanks, a working sample is the easiest way to learn :)

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.

Follow this Question

Answers Answers and Comments

14 People are following this question.

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

Related Questions

Create animation transitions via script. 0 Answers

Animation is not playing when using ragdoll physics 1 Answer

Mecanim and Ragdoll Issues? 2 Answers

Mecanim transitions for sprite prefabs 0 Answers

How should I make a animate fully physics based Active Ragdoll? 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