- Home /
need trigger + collide
Hi there. i have some [fireBall] which have rigidbody and checked as Is Trigger.
Then player have code like this:
unction OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "respawnPoint") { dead = true; HealthControl.LIVES -= 1; }
if(hit.gameObject.tag == "enemyProjectile")
{
gotHit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
everything is fine, just how should i do, that fireBall would collide on walls or terain? Becouse now fireBall is going through terain, walls, mountains, etc..
Thank you very much.
Answer by aldonaletto · Jun 22, 2011 at 04:48 AM
This is happening because you've set Is Trigger to true. It seems you need a trigger to detect "respawnPoint", but usually it's not a good thing the "enemyProjectile" to be a trigger. Uncheck Is Trigger in the FireBall object and detect it in OnCollisionEnter (or OnControllerColliiderHit, if the player is a Character Controller):
function OnTriggerEnter( hit : Collider ) {
if(hit.gameObject.tag == "respawnPoint") {
dead = true;
HealthControl.LIVES -= 1;
}
function OnCollisionEnter( hit : Collision ) {
// function OnControllerColliderHit( hit : ControllerColliderHit) {
if(hit.gameObject.tag == "enemyProjectile") {
gotHit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
Answer by kropcik · Jun 22, 2011 at 10:57 AM
Yeah, firstly i used: OnControllerColliderHit( hit : ControllerColliderHit)
but problem is If i want the code to work with OnControllerColliderHit (), i need to move with my playerCharacterController. If I stand still, when enemyProjectile hits player, nothing happens.
Your answer
Follow this Question
Related Questions
Problems destroying object on collision with Terrain 3 Answers
Terrain - Detect collision coordinates? 1 Answer
Falling through parts of terrain. Unity 5 0 Answers
[SOLVED] Unity 5 - Runtime Terrain Deformation Collider Bug 4 Answers
How can I perform some action based on the terrain texture currently under my player? 4 Answers