Search Unity

Collider issues... :(

Discussion in 'Scripting' started by tecra134, Feb 22, 2013.

  1. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    I'm not sure what I'm doing wrong... I've done this before on other projects and it worked fine. So my issue right now is when Object A hits Object B nothing happens...

    I wanted to reach out to the community to make sure that I have everything set up correctly.

    In Unity I have two game objects. objectA has just a box collider(Is Trigger is unchecked), Mesh Renderer and a script attached to it. objectA is also being instantiated upon a key press. objectB has a box collider(Is Trigger is CHECKED), Mesh Renderer and a script attached to it.

    What I want to happen here is simple. When objectA collides with objectB, something will happen.

    The script attached to objectA only has code to make it move via transform.translate.

    Below is what I have for objectB script.

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. function OnTriggerStay(other:Collider)
    5. {
    6.      if(other.gameObject == GameObject.Find("objectA"))
    7.      {
    8.           //do something
    9.      }
    10. }
    11.  
    Am I missing a step that I've forgotten or shouldn't this be working?
     
  2. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    Blah. Of course I figure it out after I post something... I was missing a rigibody...
     
  3. tecra134

    tecra134

    Joined:
    Mar 19, 2011
    Posts:
    94
    Okay - Now my issue is that it seems my game objects are moving to fast for the script to pick it up. What's the best way to fix this? So objectA moving at a speed of 8 will get picked up by the collider/trigger. But...if objectA is moving at a speed of 16 it passes right through the trigger/collider without anything happening....
     
  4. Ribosome

    Ribosome

    Joined:
    Jan 15, 2013
    Posts:
    43
    I think this is a Frame Miss issue , you might want to Raycast to check collision in stead
     
  5. EliteMossy

    EliteMossy

    Joined:
    Dec 2, 2012
    Posts:
    513
    You could use OnTriggerEnter not OnTriggerStay, also use a tag not GameObject.Find as the latter is slower.