Problem with OnTriggerEnter...

I’m working on an Endless runner and I have a wall to destroy(later on deactivate instead of destroy…)the gameobjects the player doesn’t collect, but I’m having trouble getting my “Coins” to be destroyed when hitting my “Wall”…I have a runner script that is working perfectly. I’ve even used that script on my “Wall”, but it will only destroy the coins and register as an OnTriggerEnter. If you toggle isTrigger on the wall while the scene is playing or if the wall is moving with some sort of force. If I manually move the wall up and down in the editor while the scene is playing. It will trigger the function. Can the OnTriggerEnter be used on static(non-moving) objects?

Here’s the setup:

  • Coin isTrigger
  • Coin is Tagged with “coin”
  • Wall has RigidBody

Wall Script:

function OnTriggerEnter (other : Collider){
	if(other.tag == "coin"){
		Destroy(other.gameObject);
	}
}

Coin Script:

function Update () {
    	transform.Rotate(Vector3.left * Time.deltaTime * 75);
    }

(An empty game object is over each coin to move the coin forward. Otherwise it moves in a circle because of the transform.Rotate above. I’ll find a better way for this later, but i’ve tested it without the parent and it still doesn’t trigger the function.)

Hopefully I didn’t leave anything out. Please don’t hesitate to ask for more details :slight_smile:

What kind of Collision Detection is selected in your Rigidbody on the Wall? Have you tried Continuous? If the coins are moving too fast, that might be the problem.

You should add kinematic rigidbodies to the coins. A static trigger can detect rigidbodies (even kinematic) or CharacterControllers that hit it - it doesn’t detect moving colliders, even if the trigger has a rigidbody.

The rule of thumb is: a collision/trigger event is generated only when a rigidbody (or CharacterController) hits a collider, not the other way around - that’s why a moving trigger must have a rigidbody (usually kinematic) to work.