- Home /
Sliding Door question
I am trying to make a nice sliding door that opens on trigger enter and stops right below the surface, and closes on trigger exit and stops back at its original position. I decided to try using rigidbody.AddForce instead of using animation because I was running into an annoying mechanic.. Anyways, here's what I got:
var door : GameObject;
var speed : float = 20000.0;
function OnTriggerEnter()
{
door.rigidbody.AddForce(Vector3.down * Time.deltaTime * speed);
}
function OnTriggerExit()
{
door.rigidbody.AddForce(Vector3.up * Time.deltaTime * speed);
}
function Update()
{
if(door.transform.position.y <= -2.5)
{
door.rigidbody.velocity = Vector3.zero;
door.transform.position = Vector3(0, -2.55, 0);
}
}
The door opens smoothly and stops exactly where it should on enter, but when I exit, the door keeps going up.. past where I need it to be. This is my first script and I feel like i'm missing one tiny puzzle piece >.< lol
Answer by Linus · Aug 14, 2013 at 04:00 PM
I think you have forgotten to stop it from going up. Just do as you did when stopping it from going down
if(door.transform.position.y >= xxxValueXXX)
I could of sworn I tried that.. it works like a charm, thank you.
Answer by Krahazik · Aug 29, 2017 at 01:12 AM
Therse seams to be an issue with the script or it is not complete as presented. I am getting a bunch of unexpected symbol errors for lines near the beginning of the script?
Your answer
Follow this Question
Related Questions
Sliding door animation question. 3 Answers
Door Opens When Not In Trigger And Sound Help 1 Answer
I am trying to make a door, when using this script nothing happens. 0 Answers
Multi Switch Door 4 Answers
How To Add A Sound Effect To A Door? 0 Answers