private void CalculateAimPosition() { float x_axis = input.GetAxis(RewiredConsts.Action.CameraHorizontal); float y_axis = input.GetAxis(RewiredConsts.Action.CameraVertical); pointerPosition += new Vector2( x_axis * mouseSensitivity, y_axis * mouseSensitivity); pointerPosition.x = Mathf.Clamp(pointerPosition.x, -Screen.width / 2, Screen.width / 2); pointerPosition.y = Mathf.Clamp(pointerPosition.y, -Screen.height / 2, Screen.height / 2); Transform cameraTr = Camera.main.transform; Vector3 forwardPosition = transform.position + cameraTr.forward * aimAheadDistance; Vector3 xyPosition = cameraTr.up * pointerPosition.y * offset + cameraTr.right * pointerPosition.x * offset; Vector3 worldPosition = forwardPosition + xyPosition; Vector2 uiPosition = Camera.main.WorldToScreenPoint(worldPosition); EventManager.Invoke <Vector3>(EventConst.GetUpdateWorldPosAim(player.ID), worldPosition); EventManager.Invoke <Vector2>(EventConst.GetUpdateUIPosAim(player.ID), uiPosition); if (debugAim != null) { debugAim.position = worldPosition; } }
// Update is called once per frame void Update() { if (input == null) { Debug.Log("still bug"); input = camera.player.input; return; } if (use_mouse_input) { float x_axis = input.GetAxis(RewiredConsts.Action.CameraHorizontal); float y_axis = input.GetAxis(RewiredConsts.Action.CameraVertical); if (invert_y_axis) { y_axis = -y_axis; } //Add the input to the pointer's position pointerPosition += new Vector2(x_axis * mouse_sensitivity_modifier, y_axis * mouse_sensitivity_modifier); } else if (use_gamepad_input) { //float x_axis = Input.GetAxis("Horizontal"); //float y_axis = Input.GetAxis("Vertical"); float x_axis = input.GetAxis(RewiredConsts.Action.CameraHorizontal); float y_axis = input.GetAxis(RewiredConsts.Action.CameraVertical); if (invert_y_axis) { y_axis = -y_axis; } pointerPosition += new Vector2(x_axis * thumbstick_speed_modifier * x_axis * x_axis, y_axis * thumbstick_speed_modifier * y_axis * y_axis); } //If the pointer returns to the center of the screen and it's not in the deadzone... if (pointer_returns_to_center && !deadzone_rect.Contains(pointerPosition)) { //If there's no input and instant snapping is on... if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0 && instant_snapping) { pointerPosition = new Vector2(Screen.width / 2, Screen.height / 2); //Place pointer at the center. } else { //Move pointer to the center (Will stop when it hits the deadzone) pointerPosition.x = Mathf.Lerp(pointerPosition.x, Screen.width / 2, center_speed * Time.deltaTime); pointerPosition.y = Mathf.Lerp(pointerPosition.y, Screen.height / 2, center_speed * Time.deltaTime); } } //Keep the pointer within the bounds of the screen. pointerPosition.x = Mathf.Clamp(pointerPosition.x, 0, Screen.width); pointerPosition.y = Mathf.Clamp(pointerPosition.y, 0, Screen.height); Vector2 centeredMousePosition = (pointerPosition * 2) - new Vector2(Screen.width, Screen.height); EventManager.Invoke <Vector2>("UpdateMousePosition", pointerPosition); EventManager.Invoke <Vector2>("UpdateCenterMousePosition", centeredMousePosition); }