Elevator issues

Alright, so I’ve built an elevator and imported it into Unity, however. I’m really struggling with a couple concepts on how to make it operate in Unity. First I thought I would use raycasting and an animation to open the doors but then the elevator will have to move down the shaft and know when to open the doors again once I hit the bottom.

I also don’t know how an animation will work with raycasting, because once I’m inside the elevator, I have to make sure the doors won’t open again if it detects me moving around inside.

Once I get off the elevator, I should be able to move around in the next room and take as much time as I need until I get back to it without it moving back up and leaving me behind. This again makes me think that animations are out of the equation.

So, I need to be able to:

  1. approach the elevator and have the door open. (raycasting)???
  2. move down the shaft without the elevator doors reopening on me.
  3. Once I’m in the next room, I should be able to return to the elevator and go back up with no problem. (perhaps a box or sphere collider with detection)???

Since I’m still learning, I’m really stuck on this one. Please let me know. The expert advise is very much appreciated in advance!

Use a collider (invisible) that opens the door when you approach it. Basically a large box collider that triggers when a person enters that box area.

You can use colliders again, for when the doors should and shouldn’t open. So setup another collider on the second floor, that will trigger the elevator door to open.

You can set each collider to only execute actions based on what interacts with it. So, your elevator collider could look something like this:

//(pseudo code, may not compile)

function OnTriggerEnter (other : Collider) {
   
  if(other.tag == "player"){

    openDoors();


  }
}

Using colliders is cleaner and easier imho.