Okay so at the moment we have an issue with our thumbs took aim.
We can push the right frame stick in a direction and we can make the character face the direction that
we're pushing the thumbs together which is great but at the moment when we release the funds take our
character will always snap back to facing forwards.
Now we want to prevent the character from doing this.
When we release the film stick and the solution to this is to set up a fund stick dead zone.
Currently we rotate the character based on our fantastic input but we only want to rotate the character
when these funds take input values are large enough.
When I say funds stick dead zone I really just mean a range in which our thumbs stick input is ignored.
So we're only going to rotate the character when the values of our thumbs tick input are large enough
or high enough.
And if they are too low we won't even bother calling the function that rotates our character.
So how do we get started here.
Well we're going to open up our marine blueprint and inside our update play aim function and we can
actually remove the print string and the float to string conversion here.
Let's just make sure that we hook up our execution pin again to the set control rotation function.
Now we're going to proceed by creating a new function and add this function is going to check if our
thumbs to empathy lose are above the thumb stick dead zone so we can name this is fantastic.
I love that zone and we're going to start by calling our club stick em up axis value and we're also
going to get the stick aim right axis value.
Now what are we going to do with both of these values.
Well we're going to make a vector and it's going to be a vector to d the aim up is going to be the x
value and the aim right is going to be the y value.
Now a vector 2D doesn't have a z value here so we're just working with x and y with the return value
of our vector 2D.
We're going to drag this out and we're going to call the vector length function.
We're going to grab the vector 2D length here.
So this returns the length of our vector now feel free to print the return value of our 2D vector length
function as a string.
Just like I'm doing here.
And as we can see and we don't push on the thumb stick the length of our 2D vector is going to return
0.
But as we push the thumb stick in any direction the value returned is going to be 1 or above.
And if we gently release the thumb stick we can start to see that the values decrease all the way down
to zero and the zero is where our issues come in.
If we push right in the foam stick the character faces the right direction.
And as we gently release we can see that he still faces the correct direction but as soon as we hit
zero the character snaps back to facing forwards.
And this happens in any direction as well.
We're only going to allow our character to rotate if the length of our 2D vector is over a particular
value so we're going to compare the length of the vector to another float by doing this.
We are making our own thumb stick dead zone and I want you to try to finish off our function by herself
so I want you to create a variable named firm stick dead zone make it a float and give it a default
value of zero point five.
Now we're already getting the length of the 2D vector we just made in our function.
We want to do a comparison with this.
We want to compare the length of the 2D vector to see if it's greater than the thumb stick dead zone.
Once you've got this far we're not going to write any more code in this function.
Instead we're just going to return the result of this comparison as an output pin on the function.
So I want you to do this as well.
And just to wrap it up look over the code for the function check the function name.
Look at what it's doing.
Should the function be impure pure or pure contest.
Suppose here for a few minutes to set up the rest of this function
okay so with the length of our 2D vector we can compare it to see if it's greater than a value by dragging
it out and putting in the greater than symbol.
And we can get the float greater than float.
Now what do you want to compare it to.
But we want to compare it to a value that will be our thumb stick.
Dead Zone which we currently don't have.
So we're going to create it.
Let's create a new variable named from stick dead zone and let's change the variable type from a billion
to a float.
Now we can hit compile to set the default value which is going to be point five and we can plug it straight
into the second inputs on this comparison here.
So this now asks the question is the stick input greater than the farm stick dead zone.
And the answer to this will be returned in this billion pin here.
We want to output this on our function but there's no return note inside our function here to get what
we can right click and scroll all the way down and we can find this ad return note selection here and
if we select this it adds the return note and we can drag and drop our boolean onto the return note
to create a return value and we can hook up our execution in and this is our function.
The code for our function complete but now comes to the question should this function be impure pure
or pure const.
Well by looking at the name of this function we can see it's named is fantastic above dead zone.
We can tell that is named in a way that's stating its intention.
It's asking a question or doing a calculation it's just by looking at the name.
We should be thinking that this function isn't going to affect the state of our blueprint class in any
way but also by looking at the code of our function we can see that there's not much going on in terms
of the execution flow.
It's certainly not suggesting anything or affecting anything in the world.
Therefore our function can be pure const we ask the question is the foam stick are both a dead zone
and the function gives us the answer.
Now this is our function complete we can compile and we can close this tab because we don't need to
change any of the code for this anymore and we come back to our update player aim function.
Now we said that we only want to change the rotation of the character and remember we do this by setting
the control rotation of the player controller.
We only want to change the rotation if our thumb stick is above the dead zone so we're going to call
our is fantastic above.
That's a function that we just wrote.
We can drag it onto the graph.
We can hold down b and left click to place a branch on the graph.
We can use our function as the condition we can hook up the execution pen to this so we can see is the
stick above the dead zone.
If it is we can then set the control rotation for the character.
Awesome.
Soon as hit compile and it's safe let's come back to our level and let's try this.
The character faces forwards with no input on the right thumb stick but we can push the right frame
stick in the direction that we want the character to turn.
But if we release the form stick now the character no longer snaps back forwards.
So the thumb stick aiming is now working correctly.
Also this is really good progress.
No there's not actually anything more we need to do in terms of the foam stick aiming but we do want
to start thinking about mouse and keyboard input so we're going to start tackling this in the next lesson.