I trust you are using
void OnCollisionEnter(Collision col)
Allows you to investigate the collider properly.
First, keep track of each sword's owner in the sword's script (you do have a script that you attach to swords, right?). When a sword collides with something, you:
public Player owner; //Set this when the script initializes or in the editor.
//It should point to this sword's owner.
void OnCollisionEnter(Collision collision)
//You might want to iterate through all collision points and do this check so
//you don't miss collisions with the player if multiple collisions are registered.
Collider col = collision.collider;
Player player = col.gameObject.getComponent<Player>();
if (player != null) //We hit a player
if (player != this.owner) //If we didn't hit this sword's owner.
To set the sword's owner you can just drag & drop the owner's GameObject in the sword's owner property field. Alternatively, if you're instantiating characters dynamically at runtime, you can search for the sword's owner and set it appropriately. Here's a function that will work in any hierarchy:
private void setOwner()
Transform tr = this.transform.parent;
bool foundParent = false;
while ((tr != null) && (!foundParent))
Player player = tr.gameObject.getComponent<Player>();
if (player != null)
this.owner = player;
foundParent = true;
tr = tr.transform.parent;
This will go up in the hierarchy to find the closest Player, which becomes the sword's owner. If no suitable owner is found, the owner field keeps its default value,
null. If you can guarantee the owner of the sword is the direct parent GameObject, you can instead ditch the hierarchy travelling and just do
this.owner = this.transform.parent.gameObject.getComponent<Player>().
Do all of this inside