OnTriggerEnter function isn't firing, yet I'm not getting errors.

I have a game object that moves back and forth. The idea is that it will reach a trigger, at which point it will turn around and go the other way, until it hits another trigger and turns around again.

So I’m using the following code:

function OnTriggerEnter (hitBumper : Collider){
	print("Hello?");
	if(hitBumper.gameObject.name == "Left Bumper"){
		moveDirection = "Right";
		moveSpeed += 0.005;
		shiftTime = true;
	}
	else if(hitBumper.gameObject.name == "Right Bumper"){
		moveDirection = "Left";
		moveSpeed += 0.005;
		shiftTime = true;
	}
}

The “Hello?” bit is there to test whether or not my function is even firing. Turns out, it’s not.
I’m getting no errors whatsoever, but I’m also not getting any response from this function.

Help?

Hi!
make sure you have a collider attached to the gameobject with this script, and also make sure the collider checkbox" isTrigger" is marked.

Yep, the “bumpers” each have colliders, and each is set as a trigger. I’ve even tried giving a collider to the object itself, despite the detriment to my game that would have, and still no effect.

The object colliding with it, or the bumper, must have a rigidbody attached. Both don’t need a rigidbody, just one of the two. Two objects that have colliders will not trigger without it.

Added a rigidbody, and that seems to have done the trick.

However, this poses its own problems, and a question.

Problem being; this object is supposed to be effectively invisible. It exists simply as a guide, and the game’s enemies follow it along its path, yet the player isn’t supposed to ever see this object. With a rigidbody, it becomes possible for the player to shoot this invisible object and see their shots bounce off said invisible object.

Question being; I thought only one of the two colliders needed a rigidbody for the trigger to fire. Was I wrong there?

only one! and i would put it on the player.

Yeah that’s the documentation entry that I was referencing, and you’re very correct it explicitly says that only one of the two needs a rigidbody. Yet removing the rigidbody from either the object or the bumper ends up in my OnTriggerEnter function not firing at all.

Either way, however, so long as I make the object so tiny that players aren’t likely to shoot it, the trigger seems to work perfectly.

Thanks guys!

General rule of thumb is that you should put a ridigbody on any object that moves.

Just because a collision occurs does not mean a collision response has to be given. You can use layers and tags to filter for just the collisions you are interested in.

That makes sense, I’ll play around with layers too.