Weapon Collision (130285)

Ok so i have a player, a weapon(sword) and an enemy. The sword is attached as a child to the hand bone of the player and has a box collider. I want to detect collisions with the enemy so i can kill it.

using UnityEngine;
using System.Collections;

public class WeaponCollision : MonoBehaviour {

	void Update () {
	}

	void OnCollisionEnter(Collision col) {
		Debug.Log ("Collision");
		if (col.gameObject.tag == "Enemy") {
			Destroy(col.gameObject);
		}
	}
}

this script is attached to the weapon object, but its not working, the “Collision” is not being logged either.

Does the enemy object have a collider attached to it too?

Yes it has a Capsule Collider attached

does it pick up the collision?

I dont know, how would i check that? run the same script on the enemy object and use Debugger to log?

One of the colliders needs to be tagged "IsTrigger", is that checked on one of the colliders?

1 Answer

1

Ok, i tried using the OnTriggerEnter method and it’s working.