- Home /
how to detect if a character has fallen / problem with triggers
Hi - I have a game object (an invisible cube / plane) with a collider that is set below the game board called FallArea, and I have a trigger on this set so that if the gameobject enters this area, it will kill the character. The problem is, sometimes this thing is killing my character even when it doesn't actually enter the area? What's up with that? Is there a better way to detect a fall? This is my code on the FallObject:
function OnTriggerEnter ( other : Collider ) {
mainRef.GetComponent(EndGame).endGame(); //references a script which kills off the character
}
Answer by Chris D · Jul 20, 2011 at 04:01 PM
What you've written above will only be called when the trigger is touched but you're not telling it which touch to look out for. What this means is that any collision with that trigger will call endGame()
.
The solution is to put an if (other.gameObject.tag == "yourPlayer'sTag")
before the call to ensure that only the player falling can restart the level.
Thanks! Yeah - I had a launcher which was firing projectiles that occasionally missed the board. I guess that's what was doing it.