- Home /
how to make a solid door open and close?
i want to make a door open and close when it is clicked on while your fps controller is within a certain distance. also how do you get the animation for the door and make it play when clicked on? thnx in advance :)
p.s. im new at this and i don't know any scripting so i have absolutely no idea on how to go about learning that aswell. sigh
Answer by Ingen · Aug 01, 2012 at 08:54 PM
Hi, I can found the tut on youtube where i take this, but is good explained
anyway ask if have some problem,
please mark as answered if all work for you
/*
Instruction:
create a cube to use as hinge put where is needed, the withe cube
press f to meet it position
create a cube to use as door end re-size, the brown cube
centre the hinge at the door__________________________pic door1
parent the hinge at the door
in the inspector, centre the collider at the door re size as your need
and enable trigger___________________________________pic door2
Assign this script at the hinge
Press "f" to open and close the door
if whant change in, if(Input.GetKeyDown("f")at line 46
Make sure the main character is tagged "player"
when all work can remove Mash render and Mash Filter
*/
// 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;
}
}
Door 1
Door 2
I'll +1 this if you provide the link to the YouTube video.
I not remember the link, perhaps was of youtube.com/user/maksimum654321
but not need it if follow instruction
warning: first I have post a wrong script I re edit
Answer by DaveA · Aug 01, 2012 at 09:29 PM
There's a pack called 'Easy Doors' in the asset store should save you a lot of time for a measly 10 bucks
Answer by $$anonymous$$ · Aug 02, 2012 at 09:36 AM
Hi,
I've created this video tutorial which will answer your question.
http://www.youtube.com/watch?v=scm7r0uBepU&noredirect=1
Hope it helps.
thnx for creating this vid i will watch it and hopefully it helps
thnx :D
Are there any non-video tutorials? I try to study this stuff when I'm stuck on the train and a phone is not a good video source (besides, I like to read at my leisure)
how can i do this with E key. can you help with script changing?