private void SetDirectionVector() { Vector2 direction = new Vector2(); Vector2 rightStick = new Vector2(T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.X), T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.Y)); Vector2 leftStick = new Vector2(T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.X), T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.Y)); if (rightStick.x != 0 || rightStick.y != 0) { direction = rightStick; } else if (leftStick.x != 0 || leftStick.y != 0) { direction = leftStick; } if (direction != Vector2.zero) { _currentDirection = direction; } }
/// <summary> /// Returns a value between -stickRatio and +stickRatio in both x and y axis /// </summary> /// <returns></returns> public Vector3 GetCameraTargetOffset() { float limit = .2f; Vector3 _camoffset = new Vector3(); Vector2 rightStick = new Vector2(T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.X), T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.Y)); Vector2 leftStick = new Vector2(T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.X), T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.Y)); if (rightStick.x > limit || rightStick.x < -limit || rightStick.y > limit || rightStick.y < -limit) { _camoffset.Set(rightStick.x, 0, rightStick.y); _camoffset *= _rightStickRatio; } else if (leftStick.x > limit || leftStick.x < -limit || leftStick.y > limit || leftStick.y < -limit) { _camoffset.Set(leftStick.x, 0, leftStick.y); _camoffset *= _leftStickRatio; } return(_camoffset); }
private void Move() { Vector3 newPos = transform.position; if (_usesJoypad) { float jlx = T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.X); float jly = T_Inputs.GetJoystickAxis(JOYSTICK.L, AXIS.Y); float jrx = T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.X); float jry = T_Inputs.GetJoystickAxis(JOYSTICK.R, AXIS.Y); Vector2 jl = new Vector2(jlx, jly); Vector2 jr = new Vector2(jrx, jry); Vector2 jrRight = new Vector2(jry, -jrx); if (jlx != 0 || jly != 0) { newPos += new Vector3( jl.x * _moveSpeed * Time.deltaTime, 0, jl.y * _moveSpeed * Time.deltaTime ); if (jrx == 0 && jry == 0) //pas d'input stick droit { _renderAnimator.SetFloat("Sideways", 0); _renderAnimator.SetFloat("Straight", Mathf.Sqrt((jlx * jlx) + (jly * jly))); } else //input stick droit { _renderAnimator.SetFloat("Sideways", Vector2.Dot(jrRight, jl)); _renderAnimator.SetFloat("Straight", Vector2.Dot(jr, jl)); } rb.MovePosition(newPos); } else { _renderAnimator.SetFloat("Sideways", 0); _renderAnimator.SetFloat("Straight", 0); } } else { if (Input.GetKey(KeyCode.Z)) { newPos += new Vector3(0, 0, _moveSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.S)) { newPos += new Vector3(0, 0, -_moveSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.D)) { newPos += new Vector3(_moveSpeed * Time.deltaTime, 0, 0); } if (Input.GetKey(KeyCode.Q)) { newPos += new Vector3(-_moveSpeed * Time.deltaTime, 0, 0); } rb.MovePosition(newPos); } }
// Use this for initialization private void Awake() { T_Inputs.Init(); _gameState = _startingState; }