I’ve never expected that my first question here would be about colliders but i simply can’t figure that out.
I have two objects - player and enemy and i am trying to detect collision between those to. So far my OnTriggerEnter function is as simple as it can be (OnTriggerEnter (Collider col) {Debug.Log;}). My player character has the rigidbody and capsule collider in the parent object, my enemy has a collider which IsTrigger and a rigidbody which IsKinematic in parent->child->child->child object (a bone of the enemy model).
What i’ve tried so far changing colliders and rigidbodies as much as i can - no result.
Double checking for colliders, rigidbodies and IsTrigger checkbox. The player is not a trigger, the sword is, the script is attached to the player.
I checked the layer collision settings - the two layers do collide
Changing the script holder - i removed the piece of code from the player object and gave it to the sword object.
Restarting unity
I’ve been trying to figure out that for a few hours now and still can’t get it working. Any help would be appreciated!
Thanks in advance
Are you just doing “Debug.log;” or are you attaching a message to the function?
If you have a Collider on both objects, and one of them is a trigger with the script attached to it, such as:
“void OnTriggerEnter() { Debug.Log(“Hit”); }”
Then I see no apparent issues. If both of your colliders are triggers, you will need those rigidbodies.
Make sure the enemy has IsTrigger selected, Make sure the Enemy has the OnTiggerEnter(Collider col) Script (The player is entering the enemys collider, not the enemy entering players collider),
How are you moving the Player and enemy because you have to use characterController.Move(); if you want colliders to work with CharacterControllers so I think you would have to use rigidbody.AddForce(Force); if you want colliders to work (I don’t usually use rigidbodys so I might be wrong)
Okay, so last night i got some progress on the problem. Appereantly on one of my scripts i set the Player Layer to be under Layermask. I managed to get it working if i attach a OnTrigger script to another object and do the check with
OnTriggerEnter is in a MonoBehaviour that is attached to the same object with the Collider component? It isn’t a case of your MonoBehaviour being on a Parent while you collider is on a child?