- Home /
Opening a door at proximity
Hi. I would like a door that opens as soon as the player get's close enough (no need to press any button). The player is a Standard Asset prefab for an FPS. To door would open vertically and go up as soon as the player get's close to it. Thanks
Answer by Persona · Nov 02, 2010 at 03:36 PM
Set up an empty game object in front of the door, make the collider a trigger, and attach an OnTriggerEnter code on it. Compare the tag of the collider and if it's "Player" tag, have the animation play and the door open.
Antonios, you could for example make a script that would slowly raise the door a certain amount. Then perhaps do the opposite on OnTriggerExit.
$$anonymous$$y animation makes the door Open and Close directly, how do I split the animations? I made them with unity so they do not appear on the FBXimporter...
Answer by MohdGasim · Nov 13, 2010 at 12:00 PM
HI....although a newbie to both Unity and scripting...i found this using Raycast, just make sure your door has a collider and Is Trigger is off....
var RayCastlenght = 2; //allows you to change the distance required to trigger the door
function update() { var hit : RaycastHit;
//check if we are colliding if(Physics.Raycast(transform.position, transform.forward, hit, RayCastlenght)) { //...check colliding with door if(hit.collider.gameObject.tag == "BookCase") {
//move the case
hit.collider.gameObject.animation.Play("BookCase_anim");
}
}
}
what you need to do is compose an animation for the door to open and then change Bookcase_anim with your new animation.....
best of luck
Your answer
Follow this Question
Related Questions
Make Object Move to another Object 1 Answer
Lerp a Object along X and Z axis only. 3 Answers
Need help getting my character to move 2 Answers