In the game, we want the user to be able to select various buttons that will open doors. To facilitate this, we split the doors off from the objects are they separate objects of their own. And by sliding them in the Zed direction, this particular one, we can slide it into the wall. We could actually add the animation to the scene itself. But we're going to look at adding some custom animation that you can dynamically in the game using tweens. So there we have the two objects that we're going to find.
Now we look at our Loader for our environments SPX. Notice how we've got a door objects, it's going to trigger set to null and proxy array and a doors array. That's because one trigger is going on two doors, because the door is acting as a pairs. If we find the child name includes door proxy, then we add it to our proxy array. And we check our door using this function here, which we'll look at in a moment. If the name includes door, very mind we've already checked the door proxy so so it can't be door proxy, it has to be door on its own.
And we push that into our doors array, and we check the door again. It's not a mash that is a simple No objects, I didn't include the name door No. And that's going to be our trigger. Once we've got a trigger and the proxies of length, the door proxies of length two, and the doors are of length two, we reassigned door and we start looking for some more sets of doors. In the game we've developed for this course, there is only one trigger and two doors. So there are only ever be one of these, but this is how you would do multiple ones of them.
So a game contains a doors array, which contains any number of objects of this form. With a trigger, proxy of length two, and doors of length two. The doors are what we see, the proxy is what we're going to use for blocking things from blocking our Ray caster. So let's have a look again at our automate function. And notice how it's looking through the doors array. Bear in mind, in this particular version of the game, there's only going to be one instance in this doors array.
And it's checking for the distance from the trigger. So the trigger is that Null Object we've created. And that's going to be what we use as the proximity test. If that's less than 100, from where we from where our player is, then we're going to show our action button and we're going to create an action that is going to push button so that's the action that our player character is going to show as an animation. The modes going to be open doors, and this instance, we're hard setting the index to zero but you would actually create a creating an index that is incremented and use the appropriate one. If you had more versions of this.
And we set trigger to true because there's only ever one trigger. So the context action can only be one thing. We use that in order to negate looking for collects because if triggers already set and we won't bother looking at it through this section, but if no triggers are set, then we're going to delete our own action property. Which brings us to context action. Now we can look more carefully at the open doors method that we saw in the previous video. Notice how we use the index value that we've got in our on action object.
We use that to find the appropriate doors object and set that to a constant called door. Left is going to be the first one of our chill children of the Doors, and right is going to be the second. And then we set a camera target and the camera target is going to be based on the position of the left door. And we do some careful repositioning. So we've got a camera in a suitable place. And then we're going to use tweens.
We'll look at the tweens again in the next video. So we will gloss over that we're adding a tween that's what's going to animate the doors to the left and to the right, depending on what which door they are. So let's have a look at how we're using camera target that's in the animate method is defined that our position is going to be whatever our camera target position is. And our target is going to be whatever our camera target is. So that's what we're going to be looking at. We're going to be looking at this particular target from this particular position, which gives us the ability to add a cutscene And then by using camera lookout, he's going to move the camera to the position defined and then look at the position we've described as the target.
Those simple changes allow us to press the button here and the doors open once the doors are finished being and we come back to the default camera