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)

3 Answers

3

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

ok thanks everybody , i find the solution , i added a rigid body and keep the sphere collider and it works

thanks <3 I had the same problem.

My code won't work. void OnCollisionEnter2D(Collision2D collision) { // Check if the collided object has the specific tag if (collision.gameObject.CompareTag("Moving Platform")) { rb.velocity += collision.gameObject.GetComponent<Rigidbody2D>().velocity; } }