0
votes

I am attempting to only have the collision continue when contacting the Player (the parent with the rigidbody), directly; and ignoring collisions with the child (a sword). the sword is tagged weapon, and the player with player.

I have searched, and cannot find a sufficient answer (C#)

void OnCollisionEnter (Collision col){
    Debug.Log("boop P" + playerNumber);
    if (col.collider.transform.tag == "Player") { 
        -stuff happens-
    }
}

This is driving me crazy and I need sleep, please help.

Edit - I solved it after ages, with a simple thing called ContactPoint.otherCollider

2

2 Answers

0
votes

The problem may be how you're checking for the tag. I usually grab the gameObject's tag directly like so.

void OnCollisionEnter(Collision col){
    if (col.gameObject.tag == "Player"){
        //stuff happens
    }
}

Or even the collider's tag.

(col.tag === "player")
0
votes

In case anyone else is struggling with this and OP's edit was too vague...

You can check to see the colliders that were hit on the GameObject calling the script using collision.contacts:

foreach (ContactPoint c in collision.contacts)
{
        Debug.Log(c.thisCollider.name);
}