Section 2 - Setting up the Scene
For our scene we will need:
- A Right Door
- A Left Door
- A Left Door Blocker
- A Right Door Blocker
- A Lighting Spot to be the Switcher
- Some objects to open the door by floating near it
- A huge box to be your door area.
This is how I laid out my scene. Arrange it the way you want,
though. It's your scene!

If you just want a bland generic scene to complete the tutorial and learn Xpresso
basics without all the needless fluff, arrange it like this:

If your doors are made up of different objects like mine, group them together to
one object, preferably a Null. Assign ALL objects you will want to "open" the
door to a Null object too, in case you want to use multiple objects.
The Door Blockers are not seen since they are inside the walls.
The Area Box must be invisible. To do this, either create a material with no color, no specular and 100% transparency and
assign it to the box, or simply disable the object
from being seen in the final render. Either way works, though I prefer the first (so
its optionally transparent in the view port too).
The Switch is a lighting spot, which can be problematic because it emits an
unwanted light in your scene. To correct this, go into the attributes window of the
Light object, find the General tab, and mark the "No Light Radiation" box.
We are done here. Moving on....
Section 3 - Making Doors Open When Something Comes Close
The first thing we will need to do is to create an XPresso function. You can assign
it to any object, but let's assign it to the Area Box for now. Right click your
Area Box in the Object Manager, select New Expression and click XPresso
Expression. Double click it. It will open the XPresso window, which should
look a little like this:

Your clean XPresso Window!
From this point onwards, I will work with a single door, and teach you how to clone the
properties to the other one later. This will make things much simpler for us in
the long term.
For our first step we will need to make the door open when something gets near
it. Do to this, all we need to do is define logic so that when the object
(called Sphere from now on to keep things simple) collides with the invisible
area box, the right door moves to the
right side.
To do this, drag-and-drop the Sphere and the Area Box to the XPresso window. It will
show nodes of them. Right click in the window, and select New Node > XPresso >
General > Collision. This is a node that, if a collision happens between the
"Inputs", will give an output of "True". If no collision happens,
the Output will be "false". Simple logic really.
We will need to connect these Object nodes to the Collision Inputs. So click on the
red button (which I will call the Output button, and the blue button the Input button) in
the upper-right of the sphere node. An array of inputs will now be made
available to you and the node that you just clicked. Select "object",
and do the same for the Area Box Node.
An Object output should appear with a red spot. Click and hold the left button
on that red spot and move it. A line will appear, allowing you to connect with an
input. Drag the line to Input 1, and a connection will appear. Do the same
for the other object but with Input 2. This sets up a simple logical
configuration - i.e. when those two objects collide, the output of Collision
node will be "1", or "True". If they are not colliding, it will be "0", or
"False". Simple, huh?

PS: If your "colliding" object is in fact a group of many objects, check
"Include Children" in the Node tab of the Collision's attributes in the
attribute window.
Now the logic gets a little more complex. We need to make it so that when they collide, the door will move to the
right. Sooo.... how do we calculate this move to the right? Well, in my scene, the path the door moves is
in the X Axis (check yours separately). The door's movement, therefore, in programming
terms, can be described as:
X Axis (final) = X Axis (start) + Value where value is the rate of the movement
or, more simply:
X Axis = X Axis + y
We will need to make nodes that calculate this equation. Drag and drop the Right
Door into the scene. We will need to get it's X Position, then add a value (y) to
give the final output. Since we will be getting it's X Position, click in
the Output button and select Coordinates > Position > Position.X (or whatever
axis are you using). We now need to add the Y value to it. Right click in the XPresso window and choose
New Node > XPresso >
Calculate > Math. Ah-hah! We have a Math operator now! This is how it works - It
will catch the value of the first input and add it to the second input. It's
value will be then sent to the Output.
You can leave the second input blank, as you can manually set it to a value.
With this explained, click on the Math node and, in the attributes window's
parameter tab, type a
number in Input (2). The number you set here varies greatly with your preference
and the scene scale, so I really can't help you. My advice is to start with a
value of 1, and adjust it later if your doors open too slowly or quickly. In the Node Tab you
can adjust the Function but, since we are merely adding adding values, leave it
as add. Now connect the Position.X of the Right Door with the Math:Add
Input 1.
We want the output of this little equation to be sent directly back to the Right Door's position X
(thereby allowing additive movement along the X axis), so drag-and-drop another
Right Door node, and connect as Position.X input. Connect the Math's output with it.
Your XPresso screen should now look a little something like this:

To summarize what we have done so far: The X-axis position of the Right Door is
retrieved (node 1), added to an arbitrary
value of your choice (node 2), and then assigned back to the Right Door X-axis
position, changing it permanently (node
3).
We have now to connect both series of nodes, so that the door will only move to
the right if the sphere is colliding with the area box. Thankfully, there is an input called "On",
which ensures that nodes are only enabled if they are receiving an input of
'true'. With this in mind, click on the Input box of the last
Right-Door Node and create the 'ON' node, then connect it to the Collision Output.
You should now have something like this:

Save the Scene, and try moving the sphere inside the Area Box. If you have done
everything correctly, the right door should move to the right. If the door
absolutely won't move at all, check it all again, as you must have done
something very wrong. This is also the ideal time to check the movement speed of
your door and tweak it a little before the coding gets too hefty.
- Tutorial written by Elentor
|