Skip to content

Commit 63c1370

Browse files
feat(HowToGuides): show how to convert float action to boolean action
showing how to convert float action to boolean action
1 parent ff82c33 commit 63c1370

35 files changed

Lines changed: 1455 additions & 0 deletions

File tree

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Converting A Float Action To A Boolean Action
2+
3+
> * Level: Beginner
4+
>
5+
> * Reading Time: 5 minutes
6+
>
7+
> * Checked with: Unity 2018.3.14f1
8+
9+
## Introduction
10+
11+
Sometimes you may want to use the values from a `FloatAction` to activate or deactivate an action type. For example, pressing down the trigger axis on a controller causes an action to occur when the trigger is fully pressed down.
12+
13+
The `Input Unity Input Manager Axis Actions` provide a way of getting the varying value data from an axis but don’t really provide a way of letting us trigger something when that value reaches a specific value. This can be done by taking the float value and converting it into a boolean when the float value is within our specified bounds. We can then take this boolean value and pass it into a `Boolean Action` for hooking up events that are either on or off (true/false).
14+
15+
We can do this using the Data Type Converters provided with [Zinnia.Unity] which allow conversions from one DataType to another.
16+
17+
## Prerequisites
18+
19+
* [Install the Tilia.Input.UnityInputManager] package dependency in to your [Unity] project.
20+
21+
## Let's Start
22+
23+
### Step 1
24+
25+
Create a new `Cube` Unity 3D Object by selecting `Main Menu -> GameObject -> 3D Object -> Cube` and change the `Transform` properties to:
26+
27+
* Position: `X = 0`, `Y = 0`, `Z = 0`
28+
29+
![Adding A Cube](assets/images/AddingACube.png)
30+
31+
### Step 2
32+
33+
Expand the `Tilia Input UnityInputManager` Package directory in the Unity Project window and select then `Packages -> Tilia Input UnityInputManager -> Runtime -> Prefabs -> Actions` directory then drag and drop the `Input.UnityInputManager.Axis1DAction` prefab into the Hierarchy window.
34+
35+
> Be sure to use the `Input.UnityInputManager.Axis1DAction` prefab and not just add the `Unity Input Manager Axis 1D Action` component to a GameObject as the component needs linking to a `MomentProcessor` to function.
36+
37+
![Drag Axis1DActionAction To Hierarchy](assets/images/DragAxis1DActionActionToHierarchy.png)
38+
39+
### Step 3
40+
41+
Select the `Input.UnityInputManager.Axis1DAction` GameObject in the Hierarchy window and change the `Axis Name` parameter on the `Unity Input Manager Axis 1D Action` component to listen for the desired axis, in this case enter `Tilia.Input.UnityInputManager_Axis9` to listen for the Left Trigger axis on an Xbox Controller.
42+
43+
![Change Axis Name To Axis9](assets/images/ChangeAxisNameToAxis9.png)
44+
45+
### Step 4
46+
47+
Create an empty `GameObject` in the Unity Hierarchy then click the `Add Component` button and select the `Boolean Action` component. This newly created `Boolean Action` will be the action that defines when our trigger axis is true or false.
48+
49+
![Creating The Boolean Action](assets/images/CreatingTheBooleanAction.png)
50+
51+
### Step 5
52+
53+
Click the `+` symbol in the bottom right corner of the `Activated` event parameter in the `Boolean Action` component and then drag and drop the `Cube` GameObject into the box that appears and displays `None (Object)`.
54+
55+
![Drag And Drop Cube Into Boolean Action Activated Event](assets/images/DragAndDropCubeIntoBooleanActionActivatedEvent.png)
56+
57+
Select a `Function` to perform when the `Activated` event is emitted. For this example, select `GameObject -> SetActive(bool)` (be sure not to select `Dynamic bool - SetActive` for this example).
58+
59+
![Set Activated Listener To Game Object SetActive Action](assets/images/SetActivatedListenerToGameObjectSetActiveAction.png)
60+
61+
### Step 6
62+
63+
Do the same as Step 5 but for the `Deactivated` event parameter in the Boolean Action component, but tick the checkbox under the `GameObject.SetActive` function.
64+
65+
![Set Deactivated Listener To Game Object SetActive Action](assets/images/SetDeactivatedListenerToGameObjectSetActiveAction.png)
66+
67+
### Step 7
68+
69+
Click the `Add Component` button and select the `Float To Boolean` component. This newly created `Float To Boolean` will convert our float value from the trigger axis to a boolean when the value is within our defined range.
70+
71+
![Creating The Float To Boolean Action](assets/images/CreatingTheFloatToBooleanAction.png)
72+
73+
### Step 8
74+
75+
Click the `+` symbol in the bottom right corner of the `Transformed` event parameter in the `Float To Boolean` component and then drag and drop the `Boolean Action` component into the box that appears and displays `None (Object)`.
76+
77+
![Drag And Drop Boolean Action Into Float To Boolean Transformed Event](assets/images/DragAndDropBooleanActionIntoFloatToBooleanTransformedEvent.png)
78+
79+
Select a `Function` to perform when the `Transformed` event is emitted. For this example, select `Boolean Action -> Receive` (be sure to select `Dynamic bool - Receive` for this example).
80+
81+
![Set Transformed Listener To Boolean Action Receive"](assets/images/SetTransformedListenerToBooleanActionReceive.png)
82+
83+
### Step 9
84+
85+
Set the `Positive Bounds` values to `0.5` and `1` on the `Float To Boolean` component.
86+
87+
![Set Positive Bounds Values On Float To Boolean](assets/images/SetPositiveBoundsValuesOnFloatToBoolean.png)
88+
89+
### Step 10
90+
91+
Select the `Input.UnityInputManager.1DAxisAction` in the Unity Hierarchy and click the `+` symbol in the bottom right corner of the `Value Changed` event parameter in the `Unity Input Manager Axis 1D Action` component and then drag and drop the `GameObject` GameObject into the box that appears and displays `None (Object)`.
92+
93+
![Drag And Drop GameObject Into Axis 1D Action Value Changed Event](assets/images/DragAndDropGameObjectIntoAxis1DActionValueChangedEvent.png)
94+
95+
Select a `Function` to perform when the `Value Changed` event is emitted. For this example, select `Float To Boolean -> DoTransform` (be sure to select `Dynamic float - DoTransform` for this example).
96+
97+
![Set Value Changed Listener To Float To Boolean Do Transform](assets/images/SetValueChangedListenerToFloatToBooleanDoTransform.png)
98+
99+
### Done
100+
101+
Play the Unity scene and press the Left Trigger axis on the Xbox Controller and notice how the Cube will disappear when the axis passes half way. This Boolean Action can now be used to drive other output events too such as grabbing an item or even activating a pointer.
102+
103+
[Install the Tilia.Input.UnityInputManager]: ../Installation/README.md
104+
[Unity]: https://unity3d.com/

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction/README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction/assets.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction/assets/images.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
7.82 KB
Loading

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction/assets/images/AddingACube.png.meta

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
17.2 KB
Loading

Documentation/HowToGuides/ConvertingAFloatActionToABooleanAction/assets/images/ChangeAxisNameToAxis9.png.meta

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
10.6 KB
Loading

0 commit comments

Comments
 (0)