OnTriggerEnter works only in one direction
Hi. I have a problem with collision detection on my sword (capsule collider is trigger). I'm trying to do damage dealer, but OnTriggerEnter "sees" only few collisions (always from right side of enemy character (capsule collider), never left, back etc...). What can cause the problem? I thought it can be Animator but after disabling, everything works the same way as before.
void OnTriggerEnter(Collider other)
{
print("Enter " + other.gameObject);
}
EDIT Weapon is instantiated as a child of player's hand.
Answer by lgarczyn · Jan 03, 2020 at 01:47 AM
The problem is likely that your weapon's collider is affected by the animator is subtle ways. The animator will move the collider suddenly every frame, not on FixedUpdate, which may cause it to miss other colliders.
Animators also disable any rigidbody in their hierarchy, and mess with collisions.
One way to deal with it would be to have an invisible kinematic rigidbody "following" the real sword, using MovePosition and MoveRotation, with the collider of the sword on it.
It will lag one frame behind, but it shouldn't be an issue.
Answer by pigwejq · Jan 03, 2020 at 01:33 PM
I have found the real problem. That was an effect of Rigidbody attached to the Sword, beacuse the parent already had its own Rigidbody. Two Rigidbodies on one object (even if one is attached to a child) cause Colliders are not working correctly. (Sword with Rigidbody was a child of Player with Rigidbody).