- Home /
help with door script!
hi i have a problem with a door script. I want the door only opens when I look at it and are near it. now I can open it from the other side of the map: ( And I want to open the door with "fire1"
// Smothly open a door var smooth = 2.0; var DoorOpenAngle = 90.0; var DoorCloseAngle = 0.0; var open : boolean; var enter : boolean;
 //Main function
 function Update (){
 
 if(open == true){
 var target = Quaternion.Euler (0, DoorOpenAngle, 0);
 // Dampen towards the target rotation
 transform.localRotation = Quaternion.Slerp(transform.localRotation, target,
 Time.deltaTime * smooth);
 }
 
 if(open == false){
 var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
 // Dampen towards the target rotation
 transform.localRotation = Quaternion.Slerp(transform.localRotation, target1,
 Time.deltaTime * smooth);
 }
 
 if(enter == true){
 if(Input.GetKeyDown("f")){
 open = !open;
 }
 }
 }
 
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (enter) = true;
 }
 }
 
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (enter) = false;
 }
 }
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (enter) = false;
 }
 }
go to www.youtube.com look up unity 3d open door :)
Answer by markusthegamer · Aug 16, 2012 at 07:47 PM
// Smothly open a door var smooth = 2.0; var DoorOpenAngle = 90.0; var DoorCloseAngle = 0.0; var open : boolean; var enter : boolean;
//Main function function Update (){
if(open == true){ var target = Quaternion.Euler (0, DoorOpenAngle, 0); // Dampen towards the target rotation transform.localRotation = Quaternion.Slerp(transform.localRotation, target, Time.deltaTime * smooth); }
if(open == false){ var target1 = Quaternion.Euler (0, DoorCloseAngle, 0); // Dampen towards the target rotation transform.localRotation = Quaternion.Slerp(transform.localRotation, target1, Time.deltaTime * smooth); }
if(enter == true){ if(Input.GetKeyDown("f")){ open = !open; } } }
//Activate the Main function when player is near the door function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") { (enter) = true; } }
//Deactivate the Main function when player is go away from door function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") { (enter) = false; } }
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Need Help | Door Opening Script Error 1 Answer
Need a little help in script 1 Answer
my script not working..!!! 1 Answer
Trap Door Question 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                