- Home /
Rigidbody should ignore child collider
Hello, I'm having some problems with the movement system for my character. I have generic avatar setting with this bone transform hierarchy:
There is also an animator attached to the root object, which will animate the blue hierarchy. All bones have just a box collider attached, so that projectiles can hit the character. The movement rigidbody has this settings:
useGravity: true
isKinematic: false
constraints: freezed rotation
That settings can't be changed to kinematic, because I need the "dynamic" behaviour of the rigidbody.
Now the problem: The moved bones from the animator will affect the root rigidbody. For example the walk cycle will move the character up and down, because the leg animation will push the leg into the ground.
I tried to put the rigidbody and the colliders on separate layers, but that didn't fixed the problem.
How can I force the root rigidbody to ignore the colliders of the children? I also can't add a kinematic rigidbody to the child objects, because that will cause the root rigidbody to get crazy velocity and fly away...
I am grateful for any help!
Hi, you solved this? I have a similar problem with some colliders inner a rigidbody that are not part of compound
Answer by bakir-omarov · Jun 10, 2018 at 05:49 PM
You can use simple scripts for your main body with Movement Collider, and ignore collision with all of its children . Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnityAnswers_IgnoreChildsCollision : MonoBehaviour {
private Collider[] childrenColliders;
void Start () {
// adding all colliders to an array, but our collider will be added to !
childrenColliders = GetComponentsInChildren<Collider>();
foreach (Collider col in childrenColliders)
{
// checking if it is our collider, then skip it,
if(col != GetComponent<Collider>())
{
// if it is not our collider then ignore collision between our collider and childs collider
Physics.IgnoreCollision(col, GetComponent<Collider>());
}
}
}
}
Answer by FortisVenaliter · Feb 08, 2017 at 08:11 PM
The only way I know of would be to separate your graphics and your control. Make the rigidbody a separate object from the collision/render mesh, and then have the collision/render object match the transform of the Rigidbody each frame.
I think this would be very bad for the performance. 12 colliders for each character, multiplied by 100 characters = 1200x get and set transform each frame... I think this is not an ideal solution.
Not the colliders, the root object for the graphics.
Answer by Okido · May 11, 2019 at 10:02 PM
I know this is old but it still comes up in google so I thought I'd answer - afaik this is the easiest way to have selective interaction in your game, as it's a built in unity feature, doesn't need any code, and doesn't even take a minute to do (:
You can make things ignore each other by setting them to different layers, and having those layers ignore collisions with each other.
Click any item in Unity, then in the inspector click "Layers" (just underneath the name of the object, on the right) > "Add new layer". Make a layer for your child objects (and your parent if you only want these colliders to ignore their parent, but still interact with other things).
Select all of the children you want the parent object to ignore, and in the inspector click Layers again, then select the new layer you made for the children. Do this with the parent too, setting it to be on your parent layer.
Next, go to Edit > Project Settings > Physics. At the bottom of that menu you'll see a collision matrix. Find the check box where your parent and child layers intersect, and uncheck it.
Not a true solution, if the collider is a trigger, the rigidbody throws exceptions, if not, it's compund parts don't collide each other, but still part of the main rigidbody. Try to think about a ragdoll for example, and some parts that can be attached to the character of the ragdoll. if you don't want rewrite rigidbody and colliders, we can suggest to the unity staff to put an extra setting for colliders that need to stay out of rigidbody.
Your answer
Follow this Question
Related Questions
Character Controller children of a car: Inertia effect, delay effect, what??? 1 Answer
How do you move a character with physics when using Animator.setInteger to play the animations? 0 Answers
How does the Animator drive Rigidbody with root motion (in detail)? 1 Answer
Animate Physics. Moving a rigidbody with an animation 0 Answers
Animation causes rigidbody to move 0 Answers