• 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 zeroiq50 · Feb 26, 2015 at 02:14 AM · collidersragdoll

How do I stop a Ragdoll passing through fast moving colliders?

G'day all,

I posted this question on the Forum a few days ago but I think it is more suited to "Answers"...

I am having a little issue with my game (I use the term loosely at the moment) I have a Ragdoll character which I move, snapping to a grid, locked via the Root Joint to the Y axis... It is still pretty rough but I am getting there. The idea is to (eventually) move the little guy to avoid oncoming obstacles moving at ever increasing speeds. Pretty simple thus far but my issue at the moment is that if the approaching obstacle/GameObject is moving with any speed my Ragdoll will pass strait through it and not collect/hit/impact it...

I have attached a short video(Added as .zip) to help illustrate what I'm talking about (I am manually controlling the approaching cube...) and the 2 scripts that are on the player. Also, I have checked that all colliders are not set to Triggers, Rigidbodies are not Kinematic and "Use Gravity" is not selected.

Any help would be greatly appreciated. PS: kinda new to C# so please forgive me if my code looks odd and a little messy.

---My movement code. soon to include "Swipe".

 using UnityEngine;
 using System.Collections;
  
 public class PlayerSwipeMovement : MonoBehaviour {
  
     public float moveTime = 0.1f;
  
     //private Rigidbody rBody;
     private float inverseMoveTime;
     private Vector2 touchOrigin = -Vector2.one;
     public int timer = 0;
  
     public Component[] rgdBodys;
  
     private float angDrag;
     private float oldDrag;
  
     void Start()
     {
         inverseMoveTime = 1f / moveTime;
         rgdBodys = GetComponentsInChildren<Rigidbody>();
     }
  
     void Move(int xDir, int zDir)
     {
         if(rgdBodys.Length == 0)
         {
             rgdBodys = GetComponentsInChildren<Rigidbody>();
         }
  
         if(xDir > 0)
             xDir = 1;
         if(xDir < 0)
             xDir = - 1;
         if(zDir > 0)
             zDir =  1;
         if(zDir < 0)
             zDir =  - 1;
  
         float newX = transform.position.x + xDir;
         float newZ = transform.position.z + zDir;
  
         Vector3 start = new Vector3(transform.position.x, 0, transform.position.z);
         Vector3 end = new Vector3(newX, 0, newZ);
  
         foreach(Rigidbody rBody in rgdBodys)
         {
             angDrag = rBody.GetComponent<Rigidbody>().angularDrag;
             oldDrag = rBody.GetComponent<Rigidbody>().drag;
             rBody.angularDrag = 1.0f;
             rBody.drag = 3.0f;
             rBody.MovePosition(end);
  
             if(rBody.position == end)
             {
                 rBody.drag = oldDrag;
                 rBody.angularDrag = angDrag;
             }
         }
         return;
  
     }
  
  
     // Update is called once per frame
     void Update () {
    
         int horizontal = 0;
         int vertical = 0;
  
         horizontal = (int)Input.GetAxisRaw("Horizontal");
         vertical = (int)Input.GetAxisRaw("Vertical");
  
  
         if(timer == 0)
         {
             if(horizontal != 0)
                 vertical = 0;
  
             if(horizontal != 0 || vertical != 0)
                 Move(horizontal, vertical);
         }
         if(!Input.anyKey)
         {
             timer = 0;
         }
         else
         {
             timer += 1;
         }
     }
  
  
 }



---A little code to add some random movement to the limbs.

     public class RagdollForceScript : MonoBehaviour {
      
         public float force = 0.0f;
         public float lowForce = -0.05f;
         public float highForce = 0.05f;
         public int counter = 0;
      
         public Component[] rbLimbs;
      
      
         // Use this for initialization
         void Awake () {
        
             rbLimbs = GetComponentsInChildren<Rigidbody>();
      
        
         }
        
         // Update is called once per frame
         void FixedUpdate () {
        
             force = Random.Range(lowForce, highForce);
      
             if(counter > 2)
             {
                 foreach(Rigidbody rb in rbLimbs)
                 {
                     rb.AddForce(force,force,force);
                     counter = 0;
                 }
             }
             else
             {
                 counter ++;
             }
         }
     }
 

link text

fallerragdolltest1.zip (366.7 kB)
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.

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

2 People are following this question.

avatar image avatar image

Related Questions

Ragdoll help 0 Answers

physics.OverlapSphere colliders 1 Answer

create character colliders automatically 0 Answers

How can I disable the collider collision of a ragdolls specific bones? 0 Answers

Ragdoll stucks in objects 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