- Home /
Trigger Colission not only works sometimes
Hi lovely people of the Unity community,
I have a trigger problem. I have a sphere, with a sphere collider. This Collider is a trigger, because i dont want it to react to any physics. Then i have a second game object, a box with the tag Enemy. This box has a rigidbody.
The problem is that when the sphere trigger collides with the rigidbody of the Enemy object, the collision doesnt do anything most of the time. The weird thing (for me) is that the code does kind of work. It only detects collisions some times, but i cant figure out why.
this is the code i'm using:
function OnTriggerStay(theCollision : Collider)
{
if (Input.GetButtonUp("Fire1"))
{
if(theCollision.tag == "Enemy")
{
Debug.Log("Hit Enemy");
}
else
{
Debug.Log("doesnt hit Enemy");
}
}
}
I tried using a few variations of onTrigger, like onTriggerEnter, -Exit and -Stay. All without success.
You should use script tags when you paste script. Just highlight the code you have in the question/answer and click the "101010" button at the top bar.
The thing with the rigidbody will get the events, is that where the script is?
This script is on the sphere, the trigger. I'll try putting it on the object with the rigidbody and get back to you. @DESTRU$$anonymous$$TORR, my apologies. I thought I did, but it didnt take the first time. Fixed it now.
Answer by Mischa · Jul 27, 2012 at 06:26 PM
Maybe your Rigidbody is sleeping and not processing any collisions. Some information about that problem (it is a feature in the first place :D) can be found here: http://docs.unity3d.com/Documentation/Components/RigidbodySleeping.html
I think thats the problem. When i added a second rigidbody, on the spere this time. When i try to hit it now, its more accurate, but it seems to only work when one of the rigidbodies is moving. Is there an alternative that i could use ins$$anonymous$$d of the trigger colliders?
actually, think i fixed it. I set the Collision Detection on Continuous and it works now. Thanks for the tip on where to look!
Your answer
![](https://koobas.hobune.stream/wayback/20220613074730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make colliders collide when Tİme Scale is zero? 1 Answer
Box mechanic: Is it possible to know when the box is closed on all margins? 1 Answer
Temporarily ignore collisions between player and enemies 2 Answers
kinematic trigger with static collider-no trigger message? 0 Answers
changing gravity OnTriggerEnter 1 Answer