How do I set fixed walking/running speed from joystick axis?

Hi, I’m trying to setup my third person character’s walking and running speed in two fixed states. So that when the left gamepad thumbstick is turned just a little bit in one direction the character will walk in a constant speed and not scale with the axis input. And when the thumbstick is above a certain axis (nearly fully in a direction) I want my character to run.

I have tried a lot of different methods, one of which works well but limits my character’s rotation to only 8 directions.

Thanks for help!

EDIT: I should add that my game is similar in style to action RPGs like the Dark Souls series, The Witcher and Assassin’s Creed when it comes to movement and camera functions. I tried the http://tombraider-dox.com/ Tomb Raider in Unreal demo and that’s the kind of movement I’m after as well. Turn the left stick a little makes you walk, almost fully makes you run. Two different speeds.

Ive done something similar previously in Unity using input from a PS3 usb controller. I only had two float variables a movespeed and turnamount. For different values of the movespeed from 0.0f to 1.0f I had different animation transitions. The movespeed was incremented or decremented by 0.25f which determined whether the character was idle, walking, running or sprinting.

In movement component set acceleration value to something like 10000, to make your character immediately walk or run.

Get stick input functions, plug axis value to print string function, and, in game, measure axis values for desired stick positions for walk and run.

Then, on stick input event, compare axis value with walk and run values, and set Movement Speed to appropriate values.

1 Like

I’ve tried getting the axis values and used them to control the speed. Which works well but gives me problems when it comes to certain degrees. Maybe a bit difficult to understand but.

X-axis goes from -1 to 1 and Y from -1 to 1. So when you print the value you get all sort of weird things like 0.627 in one direction (let’s say X) and 0.234 in Y (so the character is moving right but slightly angled forwards).

I’ve tried to add them together in order to get it to work but have only ended up with problems such as the direction being limited or in a certain direction the movement would be canceled out. I could replicate in blueprints what I have tried to show a screenshot since I’ve removed everything that hasn’t worked out for me.

Not since the character turns independently from the camera. So left thumbstick is used for speed and direction and right thumbstick for camera.

This is how I’m thinking. The outer circle being the left thumbstick’s room of motion. The red being a sort of dead zone and the yellow where the character would be walking with a constant speed. And the same for running at the near outer rim.

The axis input ranges-1 to 1 are the same as what I encountered in Unity. They should be independent of the turnamount.

Calculate turn angle as in attachment using Vertical and Horizontal inputs from the Joystick axes. One joystick can perform both turning and walking running movements.

So I used your info and have calculated the angle and radius of where the thumbstick is at. However I can’t figure out how to set a fixed speed without ending up with only 8 rotation directions. If I use the normal axis nothing has changed except for the blendspace speed. I want full control of rotation but only three constant speed variables: idle, walk, run.

If you using a blendtree like in Unity where you can smooth out your animation transitions you only need two variables to drive the animation. One for speed and the other rotation. In the blendtree you will have preset range inputs that determine whether the character is idle or walking. The same applies with the rotation animations. This simplifies the control of your character with a joystick. So you only need to get a deviation of the joystick from its centre(Distance formula) and the angle of deviation. These two values are passed to the animation blendtree which controls the characters movement.

Relook at your blendtree/Blendspace and simplify it so its only driven by two variables.

The blendspace only controls the speeds for the animations. It does not control how fast the player is moving.

There must be a way to incorporate variables into the blendspace. Unless you adding your variables in the state engine which contains a link to your blendspace.

I’ve been looking but haven’t really found a way to do that.

Have a look at this link i think they using nodes to pass in rotation and velocity components to control a complex blendspace. Setting movement variables for complex blend spaces - Animation - Unreal Engine Forums

It shouldn’t actually be so complicated. I think there is a much more simpler and elegant solution to handle this task this is why the Unreal Game engine was developed. To illustrate I was trying out a book on blueprints recently which involved the use of the artificial intelligence system in Unreal to create an enemy character define patrol points and navigational paths. The process involved is like a maze using Blackboards, Behaviour tree, AI controllers, Enemy character. In my opinion you will need to understand this game engine inside out if you want to harness its full potential or one can go back to hardcoding in c++ at least you know what you doing only it will take you ten times longer productivity wise. I recommend reading much books as possible that give hands on exposure to using Unreal. One lesson I learnt from programming is to start with something simple and gradually increase in complexity the same should apply with using the Unreal engine.

Jesus… It seems to be so much more complex than it should have to be. Now I’m also trying to get my character to lean inwards when turning and it’s all making my brain hurt.

Yes, and that is what I’m doing. I am slowly but steadily learning while making a third person game. I have combat and enemies setup but sometimes I get an idea of something I want to make. And I’ve come back to this over and over but I can’t seem to get my head around it. And whenever I don’t find documentation on what I want to achieve I get stuck. I appreciate the help! I know it can be done of course. It is used in the Tomb Raider demo I linked. And I’m sure I’m doing things way too complicated than they have to be.

Just randomly found this little setting that is pretty much the easiest solution.

https://i.imgur.com/WFukg6u.png

I struggled with the same issue, Tried the advice given here as far as I could understand it. Unfortunately no success. I ended up using an Event Tick in conjunction with the Animation BP.

In the AnimBP I set a speed variable based on value of input:

I then also set the Blend Space have my two animations walk and run, triggered at the value set in AnimBP.

Then I set the MaxWalkSpeed and MinAnalogWalkSpeed to the same amount with a tick event in the character BP:

Hope this helps someone :smiley:

You can simply Floor and Ceil the axis value so it would only be -1, 0, 1