• 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 risinghell09 · Apr 10, 2014 at 05:32 PM · physicsrigidbodyragdollkinematic

How can I make character become a ragdoll with isKinematic?

I've been trying to create a script that makes my Player become a ragdoll when you press the space bar. The Player has a ragdoll with each limb having isKinematic to true. Basically, I want to have it so that if you press the space bar, isKinematic for each limb will be set to false so that they become a ragdoll and the script player script called 'ThirdPersonController' be deactivated. Also, I was trying to have it so that after 5 seconds, the ragdoll resets to the player by activating the 'ThirdPersonController' script and setting isKinematic for the limbs to false. This isn't working as the Limbs remain with isKinematic set to true, but the boolean itself is being activated, so could somebody please help me with my script? I'm quite new to coding.

Here is my script:

 var Limbs : GameObject[];
 var IsRagdoll : boolean = false;
 
 function Update(){
     if(Input.GetKeyDown("space")){
         IsRagdoll = true;
     }
 }
 
 function RagdollActive(){
     if(IsRagdoll == true);
     {
         Limbs.isKinematic = false;
         GetComponent(ThirdPersonController).enabled = false;
     }
     
     if(IsRagdoll == false);
     {
         Limbs.isKinematic = true;
     }
 }
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

1 Reply

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

Answer by alucardj · Apr 10, 2014 at 06:24 PM

Some points :

  • isKinematic is a variable of the Rigidbody component, not the GameObject component. (this should not even compile)

  • Limbs is an array, so you must loop through each element in the array and modify each

  • the function RagDollActive is never called

  • you should not have a semicolon after an if statement (at line 11)

  • normally variable names are in camelCase, class and components are in UpperCase

You can call a function after a delay period using the Invoke command.

So here is an (untested) script. Please read through the comments to help understand what is happening :

 #pragma strict
 
 var limbs : Rigidbody[]; // an array of Rigidbody components (drag and drop in Inspector)
 var isRagdoll : boolean = false;
 
 function Update(){
     if(Input.GetKeyDown("space"))
     {
         if(!isRagdoll) // this is the same as writing if (isRagdoll==false)
         {
             RagdollActive();
         }
     }
 }
 
 function RagdollActive()
 {
     isRagdoll = true; // set ragdoll to true
     // now if space is hit while isRagdoll == true, this function won't be called
     
     for(var limb:Rigidbody in limbs) // for each limb in the array limbs
     {
         limb.isKinematic = false; // set the variable of the Rigidbody component
     }
     
     GetComponent(ThirdPersonController).enabled = false;
     
     // invoke a function after 5 seconds to reactivate object
     Invoke( "RagdollInactive", 5.0 );
 }
 
 function RagdollInactive()
 {
     for(var limb:Rigidbody in limbs) // for each limb in the array limbs
     {
         limb.isKinematic = true; // set the variable of the Rigidbody component
     }
     
     isRagdoll = false; // set ragdoll back to false
     
     GetComponent(ThirdPersonController).enabled = true;
 }


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 risinghell09 · Apr 11, 2014 at 04:57 PM 0
Share

Thank you so much, that was really bugging me; sorry for asking for help again but is there a way to have the character controller follow the ragdoll because when the player becomes a ragdoll, the character controller will remain where it was before and when the player returns to normal, they sort of warp right back to the character controller, if you see what I mean.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

23 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

Related Questions

Multiple Cars not working 1 Answer

Problems with ragdolls and no gravity 0 Answers

Disable ragdoll without changing Kinematic boolean? 2 Answers

Tracking Force Added to Kinematic Rigidbody 2 Answers

Making a falling ragdoll rigid before jump 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges