- Home /
Question by
Thana2 · Mar 08, 2020 at 12:35 AM ·
unity 5controllerjoystickplayer movementjoysticks
How do I map joystick input to run method
Hello everyone,
I just want to map my controller input to make the player run this is the code
//JoyStrick
PlayerConroles controls;
bool running=false;
private void Awake()
{
controls = new PlayerConroles();
controls.GamePlay.Run.performed += ctx => running = true;
}
void OnEnable()
{
controls.GamePlay.Enable();
}
void OnDisable()
{
controls.GamePlay.Disable();
}
void Update() {
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 inputDir = input.normalized;
running = Input.GetKey(KeyCode.LeftShift);
Move(inputDir, running);
float animationSpeedPercent = ((running) ? currentSpeed / runSpeed : currentSpeed / walkSpeed * .5f);
animator.SetFloat("speedPercent", animationSpeedPercent, speedSmoothTime, Time.deltaTime);}
I already added Run action on the action maps and mapped the joystick with the button I want and the walking part also sat up but I'm struggling to make the running boolean set to true when pressing the button.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612224548im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Joystick isn't responding? 0 Answers
Getting Joystick Input from Matricom G-Pad BX? 0 Answers
Gamecube Controller joystick axis does not work? 0 Answers
Change the position of the Joystick by tap 2 Answers
Not reading joysticks on the Nintendo switch joycon 0 Answers