Collisions Detection Functions Not Called, Walking Through Walls
Sorry for asking such a common question, but I've gone through so many answers / tutorials, but they all seem slightly different or I'm not understanding how apply those solutions to my problem.
The GameObjects:
1. A wall with box collider that is enabled and is not a trigger. The wall has no rigidbody.
2. An animated character with many rigidbody and collider components so that animation can be turned off and he can ragdoll.
What works:
The animations look great, the conversion to ragdoll looks great, the character's feet stay solid on the floor. Many hours of experimenting and reading to figure all that out.
What doesn't work:
Collisions are not detected with the wall (or other characters). The character walks right through and the character's functions for OnCollisionEnter (or OnTriggerEnter) do not get called.
What I've tried:
I've tried setting the 4 variables below in different combinations it to get collisions working. None seem to help.
What am I not understanding?
protected void EnableCollisionDetection()
{
foreach (Rigidbody rb in gameObject.GetComponentsInChildren<Rigidbody>())
{
rb.isKinematic = false;
rb.detectCollisions = true;
}
foreach (Collider c in gameObject.GetComponentsInChildren<Collider>())
{
c.enabled = true;
c.isTrigger = true;
}
}
Answer by lgarczyn · Dec 02, 2019 at 01:49 AM
IsKinematic should be false unless you check for collisions using a raycast by hand.
IsTrigger should definitely be false if you want to interact with the world.
If you use a dynamic rigidbody, you should use AddForce
or .velocity
, not MovePosition
nor .position
.
Also check
Layers
IgnoreCollision calls
MeshColliders with rigidbodies
Thanks for the response.
- I have tried is$$anonymous$$inematic false along with isTrigger false.
- I have only the default layer
- I have no mesh colliders, only simple ones
- I don't have any code to IgnoreCollisions, and I double checked the Project Settings to make sure all collision detection types are on.
- The character is moved by the animation, no force or scripted movement involved.
- What's a dynamic rigidbody? Do you mean Collision Detection on the Rigidbody set to Continuous Dynamic? If that is the case, no, I have it set to discrete since I don't have any fast moving objects or needs for precision collision detection.
Any other ideas? $$anonymous$$eep em co$$anonymous$$g! $$anonymous$$uch Obliged!
Animations ignore physics. You can animate the mesh of a rigidbody, you can animate kinematic rigidbodies so that they affect the world but are unaffected, but you cannot animate a rigidbody around and hope they react to walls or ceilings.
Animations don't allow for any freedom of movement, they just set a position. I'm not sure what you were expecting to get.
A dynamic rigidbody is just a non-kinematic rigidbody.
You can try continuous collision detection to increase the chance of the rigidbody 'winning' against the animation, but it has nearly no chance of working.
@ceandros It sounds like you are suggesting that it is not possible for colliders on an animated game object to interact with colliders of other game objects, and that is a very misguided statement.
Answer by adityalearnstofly · Jul 05, 2020 at 04:01 PM
In my case, I add a character controller on the animated object. I have this zombie character that has animation when get hit. When this zombie dies, I disable the character controller, animator, and iskinematic. When the zombie is still alive the collisions work well because of the character controller. But when it dies, the ragdoll also works well because the character controller, animator and iskinematic is set to disable
Thanks for the reply. I got stuck on this issue and just called it quits eventually. I'm an experienced developer, but I really struggle with Unity.
Since you use a ragdoll, I assume you have colliders on individual body parts. Are they disabled when the character is animated? Do you have a main capsule collider for when the character is animated? Do you $$anonymous$$d providing a screenshot of your game object hierarchy?