Basic tutorial - Level Slider
- 1 Project goal
- 2 Project overview
- 3 Step 1. Create a Kinematic Controller.
- 4 Step 2. Add a Slide Switch to the Slider
- 5 Step 3. Create a Spline for the Prismatic Joint of the Slide Switch.
- 6 Step 4. Set the Switch States of the Slide Switch.
- 7 Step 5. Add an Indicator Light to all three LED’s
- 8 Step 6. Use the Switch States to turn on the LED’s
To get started, first download the Tutorial Project
This is what you will learn to make in this tutorial
Project goal
The goal of this basic tutorial is to rig a level slider which lights up LED’s when the level is slid up.
Create a Kinematic Controller.
Add a Slide Switch to the Slider
Create a Spline for the Prismatic Joint of the Slide Switch.
Set the Switch States of the Slide Switch.
Add an Indicator Light to all three LED’s
Use the Switch States to turn on the LED’s
Project overview
The project consists of a predesigned model that has been optimized and correctly put into the Hierarchy. Textual reference has been added to each of the steps, please find these under the Level Slider Tutorial. The textual reference is displayed in the Inspector.
You can find the correct scene in the Tutorial Project under
Assets > 1 - Basic Tutorials > 1 - Level Slider Tutorial > 1 - Exercise - Level Slider Tutorial
3d-model of the level slider (included with the tutorial)
Hierarchy setup
For reference, the finished setup has also been provided. Open the scene: 1 - Finished - Level Slider Tutorial under Assets > 1 - Basic Tutorials > 1 - Level Slider Tutorial
Step 1. Create a Kinematic Controller.
If you want to use Kinematics, you will firstly need a https://unit040.atlassian.net/wiki/spaces/PUD/pages/280954380 This component controls all Kinematic Transforms in the scene.
To create a Kinematics Controller, go to Mechanics > Add Kinematics > Kinematics Controller.
The Kinematics Controller will be automatically assigned to the selected GameObject, or when there is no GameObject selected, a new one will be automatically created.
Make sure to place the Kinematic Controller above the parts you want to control, in this case the Level Slider. Drag the Level Slider onto the NEW_KINEMATICSCONTROLLER.
Step 2. Add a Slide Switch to the Slider
To create a https://unit040.atlassian.net/wiki/spaces/PUD/pages/280855910 and assign it to a GameObject, select the GameObject and go to Standard Components > Slide Switch > Add Physical Component. In this case, select the Slider and add a Slide Switch.
The Slide Switch is automatically created with a https://unit040.atlassian.net/wiki/spaces/PUD/pages/281051887 attached to it.
Step 3. Create a Spline for the Prismatic Joint of the Slide Switch.
To create a https://unit040.atlassian.net/wiki/pages/createpage.action?spaceKey=PUD&title=Spline&linkCreation=true&fromPageId=281706729 , go to Utilities > Create > Spline.
The NEW_SPLINE will be created with two control Points.
We are going to use the Spline to control and limit the range of motion of the Slider. We want the Slider to stay inside its slot when moving.
To position the spline properly, parent the spline under Panel so it has the same parent as the Slider. Set the rotation of the Spline to X: 0; Y: 0; Z: -90;. To get the correct length of the Spline, bring Point[2] back in, to match the length of the Panel. Lastly, for clarity, position the entire Spline to be in the slot. Also rename the Spline to “Prismatic Spline”.
This is what your Hierarchy should now look like.
Select the Prismatic Spline under Limit Relation & Update Settings under the Slide Switch under the Prismatic Joint.
To check if your setup is correct, turn on Enforce Outside Playmode and move the Slider.
Step 4. Set the Switch States of the Slide Switch.
To set different states of the Slide Switch, move the Slider to the desired position along its Spline and click Add new state under the Slide Switch. To get a good look, position the camera to look straight on the Level Slider.
Position the Slider next to each of the LED’s and add a new Switch State for each LED. Be sure to name your states so that you keep them easily apart.
The big red dots show the position of each Switch State. Make sure you also have the positions assigned as in the image. Also with no LED next to it.
Step 5. Add an Indicator Light to all three LED’s
To make an LED light up when the slider reaches it, add an Indicator Light to each LED.
To add an https://unit040.atlassian.net/wiki/spaces/PUD/pages/280953809 , go to Standard Components > Indicator Light > Add Physical Component.
Create a Control Panel to test the functionality of the active LED.
Do this for all LED’s.
Step 6. Use the Switch States to turn on the LED’s
Now that all Switch States and LED’s have been set up correctly, we have to link them to each other.
Go to the Slider, and under Properties open up the [1] Led 1 state, corresponding to the first LED.
Under On Selected (), click the + sign to add an action. Then, select Led1 as the object for that action. Lastly, for the function, select IndicatorLight > SetActive (bool) and check the box.
This will set the LED active when the Switch State [1] Led 1 is selected.
Press Play and move the Slider to the first Switch State to test the first LED.
NOTE: If you are switched to GameView as a result of going into PlayMode, switch back to SceneView in order to be able to move the Slider.
As you can see, the LED turns on. However, it turns on halfway between State [0] and State [1]. To correct this, adjust the Lower Weight of State [1] to 0.
Next thing we need to do is to make sure the LED also turns off when it is no longer selected. The state that turns a LED off, should be the state before the one that turns the LED on.
To do this, add an action to [0] Off State On Selected (), since it is the state before [1] Led 1. As the object for this action, again select LED1. For the function, select IndicatorLight > SetActive (bool) and make sure that the box is NOT checked.
The LED should now light up as it is selected, and it should turn off as soon as it is no longer selected.
Now do this for the other LED’s also.
If you have set things up right, states should look similar to the following image
Start Play Mode and your Level Slider should work.
Prespective Documentation