• 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 mahmouds · Jun 25, 2020 at 03:19 PM · physicsragdoll

Detach Arm Body Part

So I have a robot enemy and when I shoot It with my pistol I want the game object that got shot to fall off and act as a ragdoll (kinda like in Danis Karlson game). I tried putting a script on every body part of the game object that unparents but it doesn't unparent. So my model looks exactly like Danis robot model for the game Karlson (not expecting anyone to know what that is but just in case) and when I shoot it with a bullet (not raycasted using addforce) and all its health runs out the last body part that was shot falls off. The model has bones and is using a navmeshagent and has a walking and idle animation. I am going to try to add a muti aim constraint. https://www.youtube.com/watch?v=yqmiuPF9YEU&t=161s This is the devlog of Karlson where he makes the robot and also you will see at 2:22 in the video his body parts fall off when out of health. Animations were made in unity.

Thanks any help appreciated.

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
0

Answer by Darkmatter520 · Jun 25, 2020 at 03:26 PM

You may need to detach the physics joints themselves! I believe that the parenting hierarchy does not effect physically attached rigid-bodies like a ragdoll has, it is more for organization.

So you will need to first Unparent, then access the physics joint (I think it is called a Character Joint) and disable it, or remove the component.

I am assuming your character has individual arms and legs, not all one skinned mesh right? In that case it would get slightly more complicated.

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 mahmouds · Jun 25, 2020 at 03:40 PM 0
Share

Hi, yeah so everything is separated not all one skinned mesh.

avatar image
0

Answer by tuinal · Jun 25, 2020 at 03:51 PM

If it's an animated unrigged character:

Add a script per part with a callback to a base script on the root. This is easier than trying to manage/store part lists centrally & can be easily extended to give different hp/armor to different parts, or make certain parts nondetachable simply by not attaching the script, e.g.

 public class BotPart : MonoBehaviour
 {
     BotAI controller;
     private void Awake()
     {
         controller = GetComponentInParent<BotAI>();
     }
     public void TakeHit()
     {
         controller.PartHit(gameObject);
     }
 }
 

However, it's usually better to manage most of the behaviour centrally, because you'll have a single animator and usually need to adjust the AI and animation behaviour if, for example, a leg is missing. So in a single BotAI script on the root;

 public void PartHit(GameObject part)
        {
         Destroy(part.GetComponent<ConfigurableJoint>()); //remove appropriate joint to stop the physical joint
         part.transform.parent = null; //clear parent to stop the animation
         anim.Rebind(); //where anim is the animator. This ensures detached bits stop animating. Clearing parent alone may not work.
         part.GetComponent<RigidBody>().isKinematic = false; //rb should be set to kinematic when animating. This reverses that meaning it will fall. You may want to do this recursively foreach child of the detaching object.

        }
 

When your gun raycasts, do

  if(hit.collider.GetComponent<BotPart>!=null) {hit.collider.GetComponent<BotPart>().TakeHit();}
 

As the poster above notes if it's a SkinnedMesh (e.g a zombie) this is considerably more complicated; the only way to 'detach' a part of a skinned mesh is to set it's bone scale to 0, and spawn a new separate mesh for the bit that's blown off.

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 mahmouds · Jun 25, 2020 at 05:34 PM 0
Share

Ok, so I am extremely confused by this, I think I should explain myself a bit better, I am going to update my question.

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

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

Related Questions

How do you turn on Ragdoll physics mid-game? 1 Answer

How to Control A Ragdoll 1 Answer

How to apply joint's inverse forces to another body 1 Answer

2D Ragdoll 1 Answer

How can I make character become a ragdoll with isKinematic? 1 Answer


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