- Home /
Collider won't collide with a trigger
Hi , i have a shoot that's make a spherical shock , and the shock causes an amount of damage every second , it works with my character but it wouldn't work with a cannon , the cannon have a collider and a trigger , this is the colliding code of the cannon
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Shoot")
{
collision.gameObject.BroadcastMessage("Hit",gameObject);
}
if(collision.gameObject.tag == "SmallShoot")
{
collision.gameObject.BroadcastMessage("Hit",gameObject);
}
if(collision.gameObject.tag == "Hit")
{
collision.gameObject.BroadcastMessage("Hit",gameObject);
}
}
function OnTriggerEnter(Hit : Collider)
{
if(Hit.gameObject.tag == "Trap")
{
Hit.gameObject.BroadcastMessage("Hit",gameObject);
Damaged = true;
}
if(Hit.gameObject.tag == "Shoot")
{
Hit.gameObject.BroadcastMessage("Hit",gameObject);
Damaged = true;
}
if(Hit.gameObject.tag == "SmallShoot")
{
Hit.gameObject.BroadcastMessage("Hit",gameObject);
}
}
function OnTriggerStay(Stay : Collider)
{
if(Stay.gameObject.tag == "SmallShoot")
{
Stay.gameObject.BroadcastMessage("Hit",gameObject,SendMessageOptions.DontRequireReceiver);
}
}
function Damage (Damage : float )
{
if(!NoHealth)
{
Health.localScale.x -= Damage / (Sturdy * 0.1);
}
if(NoHealth)
{
Instantiate(Destroyed,transform.position,transform.rotation);
Destroy(gameObject);
}
}
and thanks very much
Please- code-dumps are pretty ugly when they're that badly formatted. (they're pretty ugly anyway, because nobody wants to look through an entire script to find the one line that's making an error)
Answer by Ludiares.du · Oct 09, 2011 at 02:07 PM
If you're using a trigger, use OnTriggerEnter function instead of using OnCollisionEnter
iam using a sphere collider as a normal collider and a box collider as a trigger
Answer by Subhi · Oct 09, 2011 at 04:09 PM
ok thanks everybody , i find the solution , i added a rigid body and keep the sphere collider and it works
Your answer
Follow this Question
Related Questions
OnTriggerEnter Not Working 3 Answers
Collision detection accuracy issues. 1 Answer
Collission and Trigger on Same object 0 Answers