Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Object goes through player when animating?

Discussion in 'Animation' started by Quist, Sep 27, 2014.

  1. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    So i have a cabinet and in there i got wing1 "the left" and wing2 "the right".
    But when it starts animating it goes directly through my player?

    I have a door with the same script, and the door has the exact same components attached but it works on the door and not the closet, why?

    Picture:



    Script:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var theLeftCloset : Transform;
    4. var closetIsClosed = true;
    5. private var drawGUI = false;
    6.  
    7. function Update ()
    8. {
    9.     if (drawGUI == true && Input.GetKeyDown("mouse 0") && closetIsClosed == true)
    10.     {
    11.            TheClosetOpens();
    12.     }
    13.     if (drawGUI == true && Input.GetKeyDown("mouse 0") && closetIsClosed == false)
    14.     {
    15.         TheClosetCloses();
    16.     }
    17. }
    18.  
    19. function OnTriggerEnter (theCollider : Collider)
    20. {
    21.     if (theCollider.tag == "Player")
    22.     {
    23.         drawGUI = true;
    24.     }
    25. }
    26.  
    27. function OnTriggerExit (theCollider : Collider)
    28. {
    29.     if (theCollider.tag == "Player")
    30.     {
    31.         drawGUI = false;
    32.     }
    33. }
    34.  
    35. function OnGUI ()
    36. {
    37.     if (drawGUI == true)
    38.     {
    39.         GUI.Box (Rect (Screen.width*0.5-50, Screen.height*0.5-25, 170, 22), "Left click to open the closet");
    40.     }
    41. }
    42.  
    43. function TheClosetOpens()
    44. {
    45.         theLeftCloset.animation.CrossFade("SmallLeftOpen");
    46.         yield WaitForSeconds(0.1);
    47.         closetIsClosed = false;
    48. }
    49.  
    50. function TheClosetCloses()
    51. {
    52.         theLeftCloset.animation.CrossFade("SmallLeftClose");
    53.         yield WaitForSeconds(0.1);
    54.         closetIsClosed = true;
    55. }
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,960
    What is the problem exactly? Your first post doesn't make it clear. Is your game 1st or 3rd person? What were you expecting to happen? To push the player back? An image showing the problem actually happen would help.

    (and posting "No one? Really?" made me not want to reply)
     
  3. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    i did say what the problem was :) ?

    When the animation starts the closet wings go through the player instead of pushing the player back.
    The game is 1st person
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Wing1's BoxCollider is set to IsTrigger, which means it won't push anything. You could add a Rigidbody and another BoxCollider with IsTrigger UNticked.
     
  5. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284