Search Unity

Multiple Vector3 in the same scene for doors opening

Discussion in 'Scripting' started by cimopimko, Apr 4, 2014.

  1. cimopimko

    cimopimko

    Joined:
    Mar 13, 2014
    Posts:
    9
    Hello Unity people!
    Apologies for my first message as a question :)
    I'm really trying to get the vector3 in my head but by now, still pretty difficult..
    Just doing some basic stuff wi)th sliding doors, i have a room with 3 doors (front wall,left wall,right wall)
    I'm using the script i'm posting below, which i've found here (thanks!)
    But i'm only able to use it on the front wall door, as as far i undesrtand the script says to the vector3 to grab the local positions from the doorL and doorL gameObject and then it stores them, so when i'm trying to attach the same script (tried diffrent name too) to the sphere collider i'm using as a trigger in front of the left wall door, my sliding doors moves on a 90 degrees rotation, in parallel as the front wall door.. same thing if i try to the door on right wall.
    i'm pretty sure that's something simple, but it'l like learning a new language, give me time ;)
    I'll appreciate any help you can give me, basically how do i tell to use a Vector3 (B) and a Vector3 (C) so it grabs the local positions from the objects i'm linking to?
    thank so much in advance!

    Here's the script:

    Code (csharp):
    1.  
    2.  
    3.  
    4. //Doors
    5. var doorL : Transform;
    6. var doorR : Transform;
    7.  
    8. //Initial positions for doors
    9. private var initialDoorL : Vector3;
    10. private var initialDoorR : Vector3;
    11.  
    12. //Control Variables
    13. var speed = 2.0;
    14. var openDistance = 2.0;
    15.  
    16. //Internal... stuff
    17. private var point = 0.0;
    18. private var opening = false;
    19.  
    20. //Record initial positions
    21. function Start ()
    22. {
    23.     initialDoorL = doorL.localPosition;
    24.     initialDoorR = doorR.localPosition;
    25. }
    26.  
    27. //Something approaching? open doors
    28. function OnTriggerEnter (other : Collider)
    29. {
    30.     opening = true;
    31. }
    32.  
    33. //Something left? close doors
    34. function OnTriggerExit (other : Collider)
    35. {
    36.     opening = false;
    37. }
    38.  
    39. //Open or close doors
    40. function Update ()
    41. {  
    42.     if(opening)
    43.         point = Mathf.Lerp(point,1.0,Time.deltaTime * speed);
    44.     else
    45.         point = Mathf.Lerp(point,0.0,Time.deltaTime * speed);
    46.    
    47.     doorL.localPosition = initialDoorL + (-Vector3.right * point * openDistance);
    48.     doorR.localPosition = initialDoorR + (Vector3.right * point * openDistance);
    49. }
    50.  
     
    Last edited: Apr 4, 2014
  2. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
  3. cimopimko

    cimopimko

    Joined:
    Mar 13, 2014
    Posts:
    9
    oooook, i feel pretty dumb right now.. thanks so much chelnok, it worked! :)