Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by b2hinkle · May 19, 2018 at 07:40 AM · arrayragdollkinematicdeathkill

How to effect all objects in an array

Hi. I have an enemy fully rigged with rigid bodies on each bone. I want it so that when his health is <=0 (which I already programmed), his rigid body in each bone will change from isKinematic true to isKinematic false (so that he becomes a ragdoll).

{

 private Animator enemyanimator;
 public GameObject enemy;

 public Component[] bonerigidbodies;


 public float health = 1;
 public void takeDamage(float amount)
 {
     health -= amount;
     if (health <= 0f)
     {
         die();
     }
 }

 void die()
 {
     enemy.GetComponent<Animator>().enabled = false;

     foreach (Rigidbody rigidbody in bonerigidbodies)
     {
         rigidbody.isKinematic = false;
     }
 }

 private void Start()
 {
     bonerigidbodies = GetComponents<Rigidbody>();

     
 }

}

Right now it only seems to make "isKinematic" false to the body part that you shoot, but not all the other body parts. For bonerigidbodies, I dragged the gameobjects of every bone into the array from the unity editor.

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 Cherno · May 19, 2018 at 08:38 AM 0
Share

If this script is for the root object, then you have to use GetComponentsInChildren to get all the RigidBody components in the hierarchy. GetComponents only searches for components in the GameObject this script is attached to. You filled the array in the editor, but you reassign the array variable in Start, so it gets overwritten. So, you could also remove the line in Start() in s$$anonymous$$d of using GetComponentsInChildren.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Marten01 · May 19, 2018 at 10:37 AM

Remove the bonerigidbodies = GetComponents<Rigidbody>(); in the Start() method.

Comment
Add comment · Show 3 · 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 b2hinkle · May 19, 2018 at 06:07 PM 0
Share

That didn't work for me. It gave me an error

avatar image Cherno b2hinkle · May 19, 2018 at 06:53 PM 1
Share
  1. Reply with comments, not by posting a new answer.

  2. Why didn't you include the error message if there was one?

avatar image spilat12 b2hinkle · May 19, 2018 at 06:59 PM 0
Share

Care to paste the error message here, please?

avatar image
0

Answer by jonnydredd · May 20, 2018 at 07:49 AM

try Rigidbody[] bonerigidbodies = gameObject.transform.root.GetComponentsInChildren<Rigidbody>();

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.

Follow this Question

Answers Answers and Comments

101 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

Related Questions

How to make is kinematic false for all children of a gameobject? 1 Answer

Ragdoll get hit by 2 Answers

Tracking Force Added to Kinematic Rigidbody 2 Answers

Problems with ragdolls and no gravity 0 Answers

Disable ragdoll without changing Kinematic boolean? 2 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