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
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;
}
}