Search Unity

Monster Home Local Position

Discussion in 'Scripting' started by TheCasual, Jan 24, 2011.

  1. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,286
    Hello everyone. I seem to have an odd issue with trigger events. I cant for the life of me get this to work. I have two gameObjects i created (started as one, but seeing as it wasnt working, i figured i would try and simplify it , with a object for each trigger i was needing.) Each one is just a trigger, one for Detecting the monsters return to its home location (this one trigger is fairly small and in the center of the second trigger) The second trigger is a fair bit larger and when the monster leaves its area, it should flag that the monster is not at home.

    Basicly , the first trigger sets AT_HOME = true (this is cause the monster will move back to this location if the player runs out of the monsters actual player detection trigger area), and to tell the monster to stop moving back home because it IS at home.

    The second trigger sets AT_HOME = false because the monster has ran to far away from home ... The monster will keep chasing the player as long as the player is still within its playerDetected trigger area. But will return as soon as the player isnt.

    Lastly though , is one other oddity, which i can not figure out either. When the monster does return to the location, it gets as far as the outer trigger, but cant seem to pass through it (and it is set as a trigger)


    Now everything works just fine , except for the returning home part. Here is the script i have attached to the inner trigger ......



    INNER TRIGGER
    Code (csharp):
    1.  
    2.  
    3. var monster : GameObject;
    4. var HomeTrigger :  int = 0;
    5. private var clone;
    6. private var logic;
    7.  
    8. function Start()
    9. {
    10.     /// lets just ensure that someone remembered to assign a monster prefab for this script to use.
    11.     if(monster)
    12.     {
    13.         clone = Instantiate(monster, transform.position, Quaternion.identity);
    14.         logic = clone.GetComponent("MonsterLogic");
    15.         logic.HomeTrigger  = HomeTrigger;
    16.         logic.AT_HOME = true;
    17.     }
    18. }
    19.  
    20.  
    21. function OnTriggerExit(other : Collider)
    22. {
    23.     if(clone)
    24.     {
    25.         if(other.gameObject.tag == "Monster")
    26.         {
    27.             logic.AT_HOME = false;
    28.             print("Monster is at home = " + logic.AT_HOME + ", and its HomeTrigger = " + logic.HomeTrigger);
    29.         }
    30.     }
    31. }
    32.  
    33.  
    and here is the code attached to the outer trigger

    OUTER TRIGGER
    Code (csharp):
    1.  
    2.  
    3. function OnCollisionEnter(other : Collision)
    4. {
    5.     print ("DETECTED");
    6.     if(other.gameObject.tag == "Monster")
    7.     {
    8.         var clone = other.gameObject;
    9.         var logic = clone.GetComponent("MonsterLogic");
    10.         logic.AT_HOME = true;
    11.         print("Monster is at home = " + logic.AT_HOME + ", and its HomeTrigger = " + logic.HomeTrigger);
    12.     }
    13.     print("Something entered CollisionEnter");
    14. }
    15.  
    16.  
    PS : i have tried several different trigger events, TriggerEnter, CollisionEnter etc, but none seem to work. Also it seems that the event is never even happening. The print DETECTED doesnt fire once. o_O Either im wayyyy to tired or just reallly foolish. When the monster leaves the outer trigger area, it most definately does print out the statement.
     
    Last edited: Jan 24, 2011