I am trying to use a sprint forward animation which only has one animation (i.e. cannot be blended). I want the user to only be able to sprint forwards and then control the direction of the sprint with the mouse. At the moment the user can hold left shift and sprint forwards using W but also play the same animation when pressing left shift and A (left),S (back) or D (right).
I was able to stop the player moving in any forward diagonal direction (W and A or W and D) as shown in the blueprint print screen below however I cannot find a way to stop the user from being able to press the A or D key and stop the sprint animation from playing or the character moving.
My failed attempts so far:
disable input when left shift and A or D are pressed and re-enable it when left shift is released.
StopMovementImmediately when left shift and A or D are pressed (kind of worked but the player slid along the floor slightly.
Check whether left shift is pressed and the value of the MoveRight Axis map is not equal 0 (i.e. left or right has been pressed) and set the value of Add Movement Input to GetMoveForward which is 0 because W hasn’t been pressed.
Check whether left shift and S key have been pressed then multiply the X and Y vector of Get MoveFowardVector by 0, re-create the vector and apply this to the World Direction.
I am pretty new, but why dont you just you branches ? i mean if Left Shift is pressed you cant set any left/right input
and if your moveforward value is negative do the same
Hi thanks for taking the time to look at this. I was able to come up with a solution myself. It’s not pretty whatsoever and I know its very badly designed but it worked as I needed it to.
It checks whether Left shift and any of the mentioned keys are pressed, then checks if any of the mentioned keys and left shift are pressed and does the same thing depending on this. If I get the time I will probably make the script alot more efficient using the method you suggested. I originally tried something like you suggested but came up with a different solution once I couldn’t get it to work.
You may wonder why I had to reverse the scripts like I did. The reason for this is because If the user holds the A key and then presses Shift the event is different to if the user presses the shift key then presses A. Therefore I had to handle both these events.
The variable can run is there because I have a stamina system but you don’t need it. I know it’s on tick but I didn’t find a way around it. Basicly what was happening was that I was able to start sprinting only when going forward but if I continued to hold shift I could sprint sideways and backward. Hope it helps and if someone find a more optimize way to do it let me know. (Don’t worry about all my errors they are there because I copy and paste from my other project and I didn’t made the variables.)