void dodgingExit() { posAtStartOfDodge = Vector3.zero; dodgeDirectionPressed = InputManager.ButtonPressed.none; mRigidbody.velocity = new Vector3(0,0,0); StartCoroutine(WaitAndEnableDodge(dodgeCooldown)); }
void checkInputDodgeing() { if (dodgeReady) { //dodge if (Input.GetKey(KeyCode.RightArrow) || Input.GetKeyDown(controllerConfig.dodgeRightButton)) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeRight; switchState(PlayerStates.dodging); } else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKeyDown(controllerConfig.dodgeLeftButton)) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeLeft; switchState(PlayerStates.dodging); } if (Input.GetKey(KeyCode.UpArrow) || Input.GetKeyDown(controllerConfig.dodgeUpButton)) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeUp; switchState(PlayerStates.dodging); } else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKeyDown(controllerConfig.dodgeDownButton)) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeDown; switchState(PlayerStates.dodging); } float RightStickHor = 0; float RightStickVer = 0; try { RightStickHor = Input.GetAxis(controllerConfig.rightStickHor); RightStickVer = Input.GetAxis(controllerConfig.rightStickVer); } catch { //no joystick plugged in } if (gameManager.isOnGrid) { if (RightStickHor > 0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeRight; switchState(PlayerStates.dodging); } else if (RightStickHor < -0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeLeft; switchState(PlayerStates.dodging); } if (RightStickVer > 0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeDown; switchState(PlayerStates.dodging); } else if (RightStickVer < -0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeUp; switchState(PlayerStates.dodging); } } else { //movement analog stick if (RightStickHor > 0.8f) { mRigidbody.velocity = new Vector3(mRigidbody.velocity.x, mRigidbody.velocity.y, speed * RightStickHor); } else if(RightStickHor < -0.8f) { mRigidbody.velocity = new Vector3(mRigidbody.velocity.x, mRigidbody.velocity.y, 0); } //movement if (RightStickVer > 0.8f) { mRigidbody.velocity = new Vector3(speed * RightStickVer, mRigidbody.velocity.y, mRigidbody.velocity.z); } else if (RightStickVer < -0.8f) { mRigidbody.velocity = new Vector3(0, mRigidbody.velocity.y, mRigidbody.velocity.z); } if (Mathf.Abs(RightStickHor) > 0.8f || Mathf.Abs(RightStickVer) > 0.8f) { transform.eulerAngles = new Vector3(transform.eulerAngles.x, Mathf.Atan2(-RightStickHor, RightStickVer) * Mathf.Rad2Deg, transform.eulerAngles.z); dodgeDirectionPressed = InputManager.ButtonPressed.dodgeForward; switchState(PlayerStates.dodging); } } if (Input.GetKeyDown(controllerConfig.dodgeForward)) { if (gameManager.isOnGrid) { float LeftStickHor = Input.GetAxis(controllerConfig.leftStickHor); float LeftStickVer = Input.GetAxis(controllerConfig.leftStickVer); if (LeftStickHor > 0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeRight; switchState(PlayerStates.dodging); } else if (LeftStickHor < -0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeLeft; switchState(PlayerStates.dodging); } if (LeftStickVer > 0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeDown; switchState(PlayerStates.dodging); } else if (LeftStickVer < -0.8f) { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeUp; switchState(PlayerStates.dodging); } } else { dodgeDirectionPressed = InputManager.ButtonPressed.dodgeForward; switchState(PlayerStates.dodging); } } } }