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 JuanseCoello · Apr 13, 2015 at 01:18 AM · rigidbodyanimationsnot workingragdoll

How can I select a ragdoll entirely as a rigidbody in animation

I am trying to make a character controller with a ragdoll. So far I have made the character move in ragdoll state with the arrows keys. The problem is that I want to add the animations, and when I do, the ragdoll becomes kinda static.

The problem I have is I want to add the movement animations. And while the character moves, I want it to have a rigidbody that acts like a general collider. I dont want to use a character controller collider. So far it works when there is no animation, like idle or run.

The main problem arises when I activate an animation. Then all the ragdoll colliders kinda like disspear, and they are not detected, when there is an animation. Why this happens???

This is my code:

 public static TP_Controller Instance;
 public static Rigidbody rb;
 public static Transform ragdoll;
 GameObject Piso = GameObject.Find("Piso");
 public LayerMask mask;


 RaycastHit hit;

 public bool isgrounded;

 // SIMPLE RAGDOLL

 Animator animator;

 public static Rigidbody[] rigidbodies;
 public static Transform[] rigidTransforms;

 Vector3[] lastRigidPositions = new Vector3[1];
 Vector3[] rigidVelocities = new Vector3[1];
 Vector3[] rigidAngularVelocities = new Vector3[1];
 Quaternion[] lastRigidRotations = new Quaternion[1];

 [Range(0f, 1f)]
 public float veclocityLerp = .2f; // If zero, then no momentum will be transferred to the ragdoll
 [Range(0f, 1f)]
 public float keepAngularMomentum = .4f; // If zero, then no angular momentum will be transferred to the ragdoll
 [Range(0f, 240f)]
 public float angularDrag = 30f; // Rigidbodies angular drag. Unitys parameter
 [Range(0f, 4f)]
 public float drag = .5f; // Rigidbodies drag. Unitys parameter
 float maxAngularVelocity = 100f; // Rigidbodies maxAngularVelocity. Unitys parameter

 public bool useGravity = false; // Ragdoll is affected by Unitys gravity
 public bool ragdolled = false; // Instantiate ragdoll with same pose and momentum as master

 

 public void Awake () // Debe quedarse en awake
 {

     

     ragdoll = transform.FindChild("Armature") as Transform;
     rb = ragdoll.GetComponentInChildren(typeof(Rigidbody)) as Rigidbody;

     Instance = this;

     animator = GetComponent<Animator>();


     rigidbodies = GetComponentsInChildren<Rigidbody>();

     int i = rigidbodies.Length;
     System.Array.Resize(ref rigidTransforms, i);
     System.Array.Resize(ref lastRigidPositions, i);
     System.Array.Resize(ref rigidVelocities, i);
     System.Array.Resize(ref lastRigidRotations, i);
     System.Array.Resize(ref rigidAngularVelocities, i);

     i = 0;
     foreach (Rigidbody rigidbody in rigidbodies)
     {
         rigidTransforms[i] = rigidbody.transform;
         i++;
     }

     i = 0;

     foreach (Transform rigidTransform in rigidTransforms) // Set some of the Unity parameters
     {
         lastRigidPositions[i] = rigidTransform.position;
         lastRigidRotations[i] = rigidTransform.rotation;

         rigidTransform.rigidbody.useGravity = useGravity;
         rigidTransform.rigidbody.angularDrag = angularDrag;
         rigidTransform.rigidbody.drag = drag;
         rigidTransform.rigidbody.maxAngularVelocity = maxAngularVelocity;
         rigidTransform.rigidbody.isKinematic = false;
         i++;

         }
     if (i == 0)
         Debug.LogWarning("There are no rigid body components on the ragdoll " + this.name);
         

 }
 

 void Update () 
 {
     if (Camera.mainCamera == null)
         return;

     GetLocomotionInput();

     TP_Motor.Instance.UpdateMotor();


     IsGrounded();



 }

 void IsGrounded()
 {

     RaycastHit hitInfo;
     if (Physics.Raycast(rb.transform.position + Vector3.down * 3f, Vector3.up * 5f, out hitInfo, Mathf.Infinity, mask))
     {


         if (hitInfo.distance > 0.1f) // Change .1f to what you need
             Debug.DrawRay(rb.transform.position + Vector3.down * 3f, Vector3.up * 5f, Color.blue);
         
         isgrounded = true;

      }
         

         if (hitInfo.distance  < 0.5f){
             Debug.DrawRay(rb.transform.position + Vector3.down * 3f, Vector3.up * 5f, Color.red);

         isgrounded = false;
     } 
  } 

 void GetLocomotionInput()
 {

     var deadZone = 0.1;

     TP_Motor.Instance.VerticalVelocity = TP_Motor.Instance.MoveVector.y;
     TP_Motor.Instance.MoveVector = Vector3.zero;

     if (TP_Controller.Instance.isgrounded != false)
     {
     if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
         TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));

     if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone)
         TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);
     }
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Ragdoll problem with animations 0 Answers

Rigidbody causes ragdoll character to fly 4 Answers

Restrict the rigidbody to be affected by only 1 joint 0 Answers

Rigidbody+collider conflicts with ragdoll structure 3 Answers

How to fix Ethan 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