Somehow not picking up trigger collisions

I have a script called Hitbox attached to a GameObject called “PlayerWeapon”. Here’s the script:

public var damage:int;
public var attackTime:float;
var StruckObjects:Array;

function OnTriggerEnter(other:Collider)
{

	 
	 if (other.gameObject.tag == "Foe")
	 {
		 var tScript = other.GetComponent("Foe");
		 tScript.TakeDamage(damage);
		 
	 }
}

It’s just supposed to check if something you collided with is tagged “Foe”, and if it is, call TakeDamage on that foe. The ‘damage’ variable is set every time you attack, and attacking is part of a completely different script.

The GameObject called PlayerWeapon has a collider marked IsTrigger that’s like, three times as wide as it and the same height…

PlayerWeapon is a parent of a little model of a sword I made (just two cylinders…).

I have a script that makes you swing the weapon in front of you, and it works fine. When I’m attacking and I check the Scene view, the collider of PlayerWeapon moves along with the sword just fine and it seems to be colliding with things, but nothing happens.

I’ve put a ‘print’ function in the TriggerEnter and also one inside the If, but neither of them print when I swing the weapon at cubes and such. I tried adding a Rigidbody to the cubes that I’m swinging at, but it still doesn’t pick anything up.

I have a Hitbox script component added to PlayerWeapon and the collider is a trigger…

What am I missing? Why isn’t either print going off?
I thought I read something about requiring a rigidbody on either colliding object for collisions to work, but I thought it was only for collisions, not trigger collisions. Besides, I’ve added rigidbodies to the cubes and it doesn’t work.

Any help would be appreciated,
Thanks!

Try adding a kinematic rigidbody to your weapon. The problem is that physics doesn't register movement of non-rigidbody objects- and so something moved by animation like that won't send trigger enter and exit messages.

I had a similar problem, actually, only worse because I wanted to get actual collision, not a message. In the end I had to create my own custom physics system just for weapon swinging- it was very simplified, but got around several of the canonical problems with Unity's physics engine (interpolation between frames, movement by animation instead of by phyisics, that kind of thing).

I would try:

var script : ScriptName;
script = other.GetComponentInChildren(ScriptName);
script.DoSomething ();

It might be that when you’re getting the Foe, it’s not actually grabbing the script?

As for printing, try Debug.Log( insert double quoted text or unquoted variable) to see what you want.