Logic Pack
11-05-2009, 05:06 AM
Tutorial 3.1 - Designing an Advanced Elevator
By comphermc (http://www.lbpcentral.com/forums/member.php?u=4697)
In this tutorial, we'll cover the process of designing an elevator with many more additional features and functions than the Basic elevator we went over in the Beginner tutorials. It will take much longer to complete, but it will also behave in a much more realistic manner. We will also design failsafes to ensure the elevator cannot be easily broken.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%281%29.jpg
First, we will construct the little elevator car that the player will ride up in. Be sure to drop into the car to ensure it has the right dimensions. Bigger or smaller elevator cars are fine and will work just the same. Give the elevator a little floor made out of dissolve. This will later act as the the trigger that causes the car to go up and down.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%282%29.jpg
Once we have the car, we will build the shaft of the elevator around it. By using the grid mode, we will ensure the elevator car will be flush with the sides of the elevator. You can make the shaft as tall as you would like. Here, we have made the bottom of the shaft out of Dark Matter so as to anchor the whole elevator.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%283%29.jpg
Move the elevator car up slightly to prepare to attach a piston to itself and the Dark Matter below. The piston will be what moves the car up and down. Before we attach the piston, we need to slightly shrink down the car to ensure it never gets stuck. We suggest turning off grid mode, selecting the car, and scaling it down ever so slightly. Even if it doesn’t look like it did much, it ensures that the car will never get stuck.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%284%29.jpg
Turn the small grid back on and attach a piston to the top of the floor of the elevator car and to the Dark Matter below. We have attached the piston in this way so that the car can be flush with the Dark Matter when it is all the way down. After you place the piston, be sure to go into a its tweak menu and set the piston to stiff. This part is important. The piston will only work if it is set to stiff. Also, while you’re in here, tweak the maximum/minimum length of the piston as well as the timing. Feel free to unpause the physics for this part, but be sure to return to pause before moving on. It is at this point you might want to add a floor for the player to get in and out of the elevator.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%285%29.jpg
Now that we have a “working” elevator, we need to set some inputs for the system. Attach a grab switch to the dissolve floor and a small magnetic key switch to the shaft of the elevator, so it is next to the car.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%286%29.jpg
Add a magnetic key right next to the magnetic key switch. Repeat this for the top of the shaft as well.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%287%29.jpg
We will want to tweak the trigger radius for these magnetic key switches to be as small as possible so that they still work (within reason). Shown here is the trigger radius for our magnetic key switches. Try to create something similar by tweaking the radius and angle.
The purpose of those last two magnetic key switches is to define the location of the elevator car. When the car is at the top, the top magnetic key will activate. Similarly the bottom magnetic key will activate when the car is at the bottom of the shaft. Now that we've got the basic design in, let's get started with the actual guts of it all.
This elevator design will address a common problem in LBP: the elevator going up (or down) without the player. The basic idea for this elevator is to control the direction of the piston controlling the elevator with a toggle switch. If you recall, a toggle switch takes a one-shot input and alternates between ON/OFF each time it is triggered. When the output for the toggle switch is set to directional, it will alternate between OUT and IN.
If we set up the toggle switch through an OR switch, then we can make the elevator change directions if the player grabs the grab switch on the elevator, or if the elevator and the player are on different floors. Consider this: the player grabs the floor, toggling the elevator to change direction, and then jumps off. The elevator will go up without them. Our logic network will recognize that the player and the elevator are on different floors and will trigger the toggle switch, bringing the elevator back down. Since there are two ways that the player and elevator can be on different floors (Sackboy is above and the elevator is below, or Sackboy is below and the elevator is above), we will need three different inputs to our OR gate.
At this point, we invite you to take a look at these logic network diagrams. The first picture is just the standard layout of how all the logic interacts. The following three pictures, then, represent the three ways that our toggle switch can be triggered.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%282%29.jpg
This is the flowchart sort of layout for our logic network.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%283%29.jpg
If we follow the diagram, keeping in mind that Green is TRUE and Red is FALSE, we can decipher what this diagram is telling us. Since the arrows coming from “Sackboy Bottom” and “Elevator Bottom” are green, we can conclude that the player and the elevator are both on the bottom floor. Also, since the arrow coming from “Grab Switch” is green, it is TRUE, so we conclude that the player has grabbed the floor of the elevator. We also see that at least one of the arrows going into the OR switch is green (from the grab switch), so by how we define an OR switch, the OR’s output will be true. Hence, the toggle is activated.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%284%29.jpg
Here we can see from the green arrows that the player is at the top and the elevator is at the bottom. Hence, the AND gate give a TRUE output, so the OR becomes TRUE, and finally the toggle is activated. This, then, causes the elevator to change to the floor in which the player is located.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%285%29.jpg
This is very similar to the last scenario. Since the player is at the bottom and the elevator is at the top, the AND gate gives a TRUE output. Hence, the OR becomes true, and the toggle is activated. This causes the elevator to change to the floor in which the player is located.
Okay, so that’s all fine and dandy. If you understood how all that works, then wiring up all the logic for this network will be much clearer. In terms of LittleBigPlanet, anywhere you see an arrow, there will be a wire. Let’s now construct our network.
----------
Firstly, we need to make sure that each of our “boxes” exists in the level. We already have our grab switch, and the magnetic key pairings for determining which floor the elevator is on, but we don’t have a way to determine where the player is located. This is not a problem – we can use a sensor switch.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%288%29.jpg
We can place a sensor switch at each floor, to sense the player’s location. Tweak the radius of this switch to be fairly large, but make sure it doesn’t reach the opposite floor. Also, set the output for this sensor switch to be directional. We now have all our network inputs, we just need to add our logic pieces.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%289%29.jpg
From the diagram, we see that we need two AND gates, a 3-way OR gate, and a TOGGLE switch. To make things clearer, we will line them up in the order that they appear on the diagram. We have decided to use the emitter based TOGGLE from the advanced pack.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2810%29.jpg
Remember, everywhere we see an arrow in our diagram, we need a wire. From this we can start wiring from left to right. The sensor switch on the top floor is wired to one of the pistons on the top AND gate. The magnetic key switch on the bottom of the elevator shaft is wired to the other piston from this same AND gate.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2811%29.jpg
Similarly, the sensor switch on the bottom floor and the magnetic key switch from the top of the elevator shaft are each wired to one of the pistons on the bottom AND gate. Note: we have removed the previous wires for clarity sake. You should not have removed any wires.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2812%29.jpg
Next, we see that the grab switch, and each of the AND gates is wired to the 3-way OR gate. Be sure to change each of these inputs to be directional and not on/off as they are set by default.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2813%29.jpg
Also, the 3 way OR gate needs to have its output changed to One-Shot and be wired to the emitter based TOGGLE gate.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2814%29.jpg
Finally, we wire the emitter based toggle to the piston holding up the elevator car. Assuming you have not messed with the settings for any of the other logic pieces, we are finished. We can now unpause. Your elevator should now be on the bottom floor and be stationary.
Feel free to drop into the level and test it out. When you grab the floor of the elevator, it should change floors. As a test of our new logic system, test out what happens if you grab the floor and then quickly jump out of the elevator. It should go without you, but when it gets to the other floor, it should toggle and come back. If this happens, then we are finished.
You can then go through and spice it up visually if you so desire.
Other Notes
Before you save the level and try to play it, delete any of the keys the emitter in the Toggle has emitted. The toggle will not work if there are any keys emitted in create mode!
If you are going to want this to be multiplayer friendly, you will probably want to set your sensor switches to be "require all"
If anything doesn't seem to work, ensure that you have not inadvertently inverted switches or set something to backwards.
Also, make sure that none of your logic pieces are interfering with other logic pieces.
You can reorganize your logic arrangement so it fits into the level more nicely. If you do, keep in mind the above suggestion.
If your elevator will not move, make sure you have not accidentally glued it to the shaft of the floor in front of it. You should be able to grab the elevator car and move it vertically within the grid. If it won't move, it is probably glued to something it shouldn't be.
Now that the guts are all organized and in place, let's start sprucing this baby up. We've split the remainder of this tutorial into optional Tweaks, which have been added as replies to this thread. We recommend doing all of the available tweaks for any single tutorial, but in the end, they're optional, so you decide.
By comphermc (http://www.lbpcentral.com/forums/member.php?u=4697)
In this tutorial, we'll cover the process of designing an elevator with many more additional features and functions than the Basic elevator we went over in the Beginner tutorials. It will take much longer to complete, but it will also behave in a much more realistic manner. We will also design failsafes to ensure the elevator cannot be easily broken.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%281%29.jpg
First, we will construct the little elevator car that the player will ride up in. Be sure to drop into the car to ensure it has the right dimensions. Bigger or smaller elevator cars are fine and will work just the same. Give the elevator a little floor made out of dissolve. This will later act as the the trigger that causes the car to go up and down.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%282%29.jpg
Once we have the car, we will build the shaft of the elevator around it. By using the grid mode, we will ensure the elevator car will be flush with the sides of the elevator. You can make the shaft as tall as you would like. Here, we have made the bottom of the shaft out of Dark Matter so as to anchor the whole elevator.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%283%29.jpg
Move the elevator car up slightly to prepare to attach a piston to itself and the Dark Matter below. The piston will be what moves the car up and down. Before we attach the piston, we need to slightly shrink down the car to ensure it never gets stuck. We suggest turning off grid mode, selecting the car, and scaling it down ever so slightly. Even if it doesn’t look like it did much, it ensures that the car will never get stuck.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%284%29.jpg
Turn the small grid back on and attach a piston to the top of the floor of the elevator car and to the Dark Matter below. We have attached the piston in this way so that the car can be flush with the Dark Matter when it is all the way down. After you place the piston, be sure to go into a its tweak menu and set the piston to stiff. This part is important. The piston will only work if it is set to stiff. Also, while you’re in here, tweak the maximum/minimum length of the piston as well as the timing. Feel free to unpause the physics for this part, but be sure to return to pause before moving on. It is at this point you might want to add a floor for the player to get in and out of the elevator.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%285%29.jpg
Now that we have a “working” elevator, we need to set some inputs for the system. Attach a grab switch to the dissolve floor and a small magnetic key switch to the shaft of the elevator, so it is next to the car.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%286%29.jpg
Add a magnetic key right next to the magnetic key switch. Repeat this for the top of the shaft as well.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%287%29.jpg
We will want to tweak the trigger radius for these magnetic key switches to be as small as possible so that they still work (within reason). Shown here is the trigger radius for our magnetic key switches. Try to create something similar by tweaking the radius and angle.
The purpose of those last two magnetic key switches is to define the location of the elevator car. When the car is at the top, the top magnetic key will activate. Similarly the bottom magnetic key will activate when the car is at the bottom of the shaft. Now that we've got the basic design in, let's get started with the actual guts of it all.
This elevator design will address a common problem in LBP: the elevator going up (or down) without the player. The basic idea for this elevator is to control the direction of the piston controlling the elevator with a toggle switch. If you recall, a toggle switch takes a one-shot input and alternates between ON/OFF each time it is triggered. When the output for the toggle switch is set to directional, it will alternate between OUT and IN.
If we set up the toggle switch through an OR switch, then we can make the elevator change directions if the player grabs the grab switch on the elevator, or if the elevator and the player are on different floors. Consider this: the player grabs the floor, toggling the elevator to change direction, and then jumps off. The elevator will go up without them. Our logic network will recognize that the player and the elevator are on different floors and will trigger the toggle switch, bringing the elevator back down. Since there are two ways that the player and elevator can be on different floors (Sackboy is above and the elevator is below, or Sackboy is below and the elevator is above), we will need three different inputs to our OR gate.
At this point, we invite you to take a look at these logic network diagrams. The first picture is just the standard layout of how all the logic interacts. The following three pictures, then, represent the three ways that our toggle switch can be triggered.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%282%29.jpg
This is the flowchart sort of layout for our logic network.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%283%29.jpg
If we follow the diagram, keeping in mind that Green is TRUE and Red is FALSE, we can decipher what this diagram is telling us. Since the arrows coming from “Sackboy Bottom” and “Elevator Bottom” are green, we can conclude that the player and the elevator are both on the bottom floor. Also, since the arrow coming from “Grab Switch” is green, it is TRUE, so we conclude that the player has grabbed the floor of the elevator. We also see that at least one of the arrows going into the OR switch is green (from the grab switch), so by how we define an OR switch, the OR’s output will be true. Hence, the toggle is activated.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%284%29.jpg
Here we can see from the green arrows that the player is at the top and the elevator is at the bottom. Hence, the AND gate give a TRUE output, so the OR becomes TRUE, and finally the toggle is activated. This, then, causes the elevator to change to the floor in which the player is located.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/diagrams/diagram%20%285%29.jpg
This is very similar to the last scenario. Since the player is at the bottom and the elevator is at the top, the AND gate gives a TRUE output. Hence, the OR becomes true, and the toggle is activated. This causes the elevator to change to the floor in which the player is located.
Okay, so that’s all fine and dandy. If you understood how all that works, then wiring up all the logic for this network will be much clearer. In terms of LittleBigPlanet, anywhere you see an arrow, there will be a wire. Let’s now construct our network.
----------
Firstly, we need to make sure that each of our “boxes” exists in the level. We already have our grab switch, and the magnetic key pairings for determining which floor the elevator is on, but we don’t have a way to determine where the player is located. This is not a problem – we can use a sensor switch.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%288%29.jpg
We can place a sensor switch at each floor, to sense the player’s location. Tweak the radius of this switch to be fairly large, but make sure it doesn’t reach the opposite floor. Also, set the output for this sensor switch to be directional. We now have all our network inputs, we just need to add our logic pieces.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%289%29.jpg
From the diagram, we see that we need two AND gates, a 3-way OR gate, and a TOGGLE switch. To make things clearer, we will line them up in the order that they appear on the diagram. We have decided to use the emitter based TOGGLE from the advanced pack.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2810%29.jpg
Remember, everywhere we see an arrow in our diagram, we need a wire. From this we can start wiring from left to right. The sensor switch on the top floor is wired to one of the pistons on the top AND gate. The magnetic key switch on the bottom of the elevator shaft is wired to the other piston from this same AND gate.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2811%29.jpg
Similarly, the sensor switch on the bottom floor and the magnetic key switch from the top of the elevator shaft are each wired to one of the pistons on the bottom AND gate. Note: we have removed the previous wires for clarity sake. You should not have removed any wires.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2812%29.jpg
Next, we see that the grab switch, and each of the AND gates is wired to the 3-way OR gate. Be sure to change each of these inputs to be directional and not on/off as they are set by default.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2813%29.jpg
Also, the 3 way OR gate needs to have its output changed to One-Shot and be wired to the emitter based TOGGLE gate.
http://www.lbpcentral.com/forums/../images/logic_pack/tutorials/3-1/3-1%20%2814%29.jpg
Finally, we wire the emitter based toggle to the piston holding up the elevator car. Assuming you have not messed with the settings for any of the other logic pieces, we are finished. We can now unpause. Your elevator should now be on the bottom floor and be stationary.
Feel free to drop into the level and test it out. When you grab the floor of the elevator, it should change floors. As a test of our new logic system, test out what happens if you grab the floor and then quickly jump out of the elevator. It should go without you, but when it gets to the other floor, it should toggle and come back. If this happens, then we are finished.
You can then go through and spice it up visually if you so desire.
Other Notes
Before you save the level and try to play it, delete any of the keys the emitter in the Toggle has emitted. The toggle will not work if there are any keys emitted in create mode!
If you are going to want this to be multiplayer friendly, you will probably want to set your sensor switches to be "require all"
If anything doesn't seem to work, ensure that you have not inadvertently inverted switches or set something to backwards.
Also, make sure that none of your logic pieces are interfering with other logic pieces.
You can reorganize your logic arrangement so it fits into the level more nicely. If you do, keep in mind the above suggestion.
If your elevator will not move, make sure you have not accidentally glued it to the shaft of the floor in front of it. You should be able to grab the elevator car and move it vertically within the grid. If it won't move, it is probably glued to something it shouldn't be.
Now that the guts are all organized and in place, let's start sprucing this baby up. We've split the remainder of this tutorial into optional Tweaks, which have been added as replies to this thread. We recommend doing all of the available tweaks for any single tutorial, but in the end, they're optional, so you decide.