How to get last full analog stick value

So, I’m getting the value of an analog stick, X and Y axes, to determine a direction. When the stick is released, I want to keep track of that direction, but releasing the stick reduces the values until 0. I’ve tried some things to fix this, but it ends up making either the X or Y axis reduce faster than the other, changing the direction.

What I’d like to do is only register values when the stick fully pushed in a direction. How would I go about doing this? Thanks.

You can use the Tick event for this. Simply create a variable to hold the highest Axis Input value, and use the Tick event to detect changes of the variable. When it is lowered, you can execute the function you wish, or just set it to maintain the direction.

I do however think that there might be another solution that can be used. You can for instance get the forward vector of a character to know what direction they are / were heading in. If you want to do this in order for characters to slide around, there might also be another method instead of what I wrote above.

The problem with the highest value method is that moving the stick will reduce/increase the values even without releasing the stick. The problem with the movement method is that, for what I’m doing, moving the stick doesn’t immediately change direction. Every possible value is used regardless of where you move the stick after all. Releasing the stick or moving it basically has no difference in terms of input values.

However, I have realized that, thanks to you: Moving the stick along the full pull increases one axis and decreases the other at every point, so I just need to check to make sure that’s maintained and check for when both are decreasing to know when it’s released. Sounds bothersome, so I hope someone has a better/implemented method, but I’ll try that for know.

Okay, so I’ve almost figured this out, but I’m having a slight problem: Rotating the stick counter-clockwise works fine, but rotating clockwise isn’t working when the stick is on the right side.

Here’s my setup:
First, I created an axis mapping for it, stick X and Y axes, but reversed the stick’s X-axis value, to insure that when either increases in value, the other decreases: Y UP is positive (1.0), while X RIGHT is negative (-1.0), which would normally be the other way around for movement. This is just for validating the stick position and is reversed back by multipling the X-axis input by -1 after validating with the following code:

bool equalValueX = currentInput.X == 1 || currentInput.X == 0;
bool equalValueY = currentInput.Y == 1 || currentInput.Y == 0;
if (currentInput.X > 0.49 || currentInput.X < -0.49 || currentInput.Y > 0.49 || currentInput.Y < -0.49) {
	if (currentInput.X > PreviousInput.X && currentInput.Y < PreviousInput.Y || currentInput.X < PreviousInput.X && currentInput.Y > PreviousInput.Y) {
		SetDirection(currentInput);
	}
	else if (currentInput.X > PreviousInput.X && currentInput.Y > PreviousInput.Y) {
		SetDirection(currentInput);
	}
	else if (equalValueX && currentInput.Y > PreviousInput.Y) {
		SetDirection(currentInput);
	}
	else if (equalValueY && currentInput.X > PreviousInput.X) {
		SetDirection(currentInput);
	}
	else if (equalValueX && currentInput.Y < PreviousInput.Y) {
		SetDirection(currentInput);
	}
	else if (equalValueY && currentInput.X < PreviousInput.X) {
		SetDirection(currentInput);
	}
}

I just need to find out why the stick on the right side isn’t working when rotating clockwise. It works seemingly perfectly otherwise.

1 Like

So, turns out it was easier than I thought, my first check was all that was needed: all I had to do was only register inputs that have either X or Y be over 0.5 or under -0.5. Any other value isn’t a full stick pull. I initially wanted to try this, but thought it’d be too easy an answer, so I never solely tried it.

bool isFullStickPull = currentInput.X > 0.49 || currentInput.X < -0.49 || currentInput.Y > 0.49 || currentInput.Y < -0.49;
if(isFullStickPull) {
    PreviousInput = currentInput;
}

I haven’t had any weird jittering from a little testing, so I think this works practically perfectly. Considering how seemingly easy this is (4 bool checks), it seems weird how I couldn’t find anything online about this nor is it just a engine function using an optimized version of this (cause I’m sure there’s at least some micro problems, even if it isn’t practical to trigger).