• 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 Cnote · Feb 11, 2015 at 07:41 PM · ragdoll

Resetting a Ragdoll for Use in an Object Pool

So I think this is a basic question, but I can't seem to figure it out.

I have a series of ragdolls, all set up in a recycling object pool.

The problem is, when they are enabled and then physics are applied to them, the ragdoll components end up in a position other than their starting point.

I have tried adding an animation to the ragdoll to reset the position every time they are used, but it doesn't seem to work.

Does anyone have a good solution for this? I really don't want to use instantiate/destroy.

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
1

Answer by Cnote · Feb 12, 2015 at 04:58 AM

Hi everyone, the answer above did help point me in the right direction, but it's not 100% correct, so I thought I would add my working script for any future people with the same issue.

 using UnityEngine;
 using System.Collections;
 
 public class Ragdolls : MonoBehaviour {
 
     public Animator zomAnim;
     public Transform pelvis;
     public Transform Lthigh;
     public Transform Lcalf;
     public Transform Rthigh;
     public Transform Rcalf;
     public Transform spine1;
     public Transform head;
     public Transform Lupperarm;
     public Transform Lforearm;
     public Transform Rupperarm;
     public Transform Rforearm;
     public Vector3 pelvisPosition;
     public Vector3 LthighPosition;
     public Vector3 LcalfPosition;
     public Vector3 RthighPosition;
     public Vector3 RcalfPosition;
     public Vector3 spine1Position;
     public Vector3 headPosition;
     public Vector3 LupperarmPosition;
     public Vector3 LforearmPosition;
     public Vector3 RupperarmPosition;
     public Vector3 RforearmPosition;
 
 
 
     void Awake()
     {
 
     }
 
     // Use this for initialization
     void Start () 
     {
         GetChildPositions ();
         StartCoroutine (ResetRagdoll());
     }
 
     void OnEnable()
     {
         GetChildPositions ();
         StartCoroutine (ResetRagdoll());
     }
 
     // Update is called once per frame
     void Update () 
     {
 
     }
 
     public IEnumerator ResetRagdoll()
     {
         yield return new WaitForSeconds(5);
         Debug.Log ("herpaderp");
         this.gameObject.SetActive (false);
         ReturnChildPositions();
         PoolMaster.Despawn(gameObject);
     }
 
     public void GetChildPositions()
     {
         pelvisPosition = pelvis.position;
         LthighPosition = Lthigh.position;
         LcalfPosition = Lcalf.position;
         RthighPosition = Rthigh.position;
         RcalfPosition = Rcalf.position;
         spine1Position = spine1.position;
         headPosition = head.position;
         LupperarmPosition = Lupperarm.position;
         LforearmPosition = Lforearm.position;
         RupperarmPosition = Rupperarm.position;
         RforearmPosition = Rforearm.position;
     }
 
     public void ReturnChildPositions()
     {
         pelvis.position = pelvisPosition;
         Lthigh.position = LthighPosition;
         Lcalf.position = LcalfPosition;
         Rthigh.position = RthighPosition;
         Rcalf.position = RcalfPosition;
         spine1.position = spine1Position;
         head.position = headPosition;
         Lupperarm.position = LupperarmPosition;
         Lforearm.position = LforearmPosition;
         Rupperarm.position = RupperarmPosition;
         Rforearm.position = RforearmPosition;
     }
 
     public void FindChildren()
     {
         pelvis = this.transform.FindChild ("Bip01 Pelvis");
         Lthigh = this.transform.FindChild ("Bip01 L Thigh");
         Lcalf = this.transform.FindChild ("Bip01 L Calf");
         Rthigh = this.transform.FindChild ("Bip01 R Thigh");
         Rcalf = this.transform.FindChild("Bip01 R Calf");
         spine1 = this.transform.FindChild ("Bip01 Spine1");
         head = this.transform.FindChild ("Bip01 Head");
         Lupperarm = this.transform.FindChild ("Bip01 L UpperArm");
         Lforearm = this.transform.FindChild ("Bip01 L Forearm");
         Rupperarm = this.transform.FindChild ("Bip01 R UpperArm");
         Rforearm = this.transform.FindChild ("Bip01 R Forearm");
     }
 }
 
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
0

Answer by tebandesade · Feb 11, 2015 at 08:48 PM

Hi! Maybe check this out, hope it works . http://forum.unity3d.com/threads/resetting-ragdoll.247435/

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.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Visualize character joint swing and twist axis script 0 Answers

Implimenting RagDoll physics with Spine Skeleton? 0 Answers

Is there any resources on making the most basic character for prototyping? 0 Answers

why does my rigged characters arms disappear when close enough 0 Answers

Character animation/ragdoll problem 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