/// <summary> /// Gets the player input. /// </summary> void GetPlayerInput() { // Read X and Y position of the mouse. mouseX += Input.GetAxis("Mouse X") * x_mouseSensitivity * (invertX ? -1 : 1); mouseY -= Input.GetAxis("Mouse Y") * y_mouseSensitivity * (invertY ? -1 : 1); // Limit the Y rotation between the specified min and max limits. mouseY = TP_Helper.ClampAngle(mouseY, minY, maxY); if (Input.GetKeyDown(KeyCode.F)) { smoothDamp = !smoothDamp; print("SmoothDamp: " + smoothDamp); } if (Input.GetKeyDown(KeyCode.V)) { FOVKick = !FOVKick; print("FOVKick: " + FOVKick); } if (Input.GetKeyDown(KeyCode.R)) { HeadBob = !HeadBob; print("HeadBob: " + HeadBob); } if (Input.GetKeyDown(KeyCode.C)) { hideCursor = !hideCursor; Cursor.lockState = hideCursor ? CursorLockMode.Locked : CursorLockMode.None; Cursor.visible = hideCursor; print("HideCursor: " + hideCursor); } }
float CheckCameraPoints(Vector3 from, Vector3 to) { var NearestDistance = -1f; RaycastHit hitInfo; TP_Helper.ClipPlanePoints clipPlanePoints = TP_Helper.ClipPlaneAtNear(to); //Draw line in the editor to make it easier to visualize Debug.DrawLine(from, to + transform.forward * -Camera.main.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperRight); if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { NearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < NearestDistance || NearestDistance == -1) { NearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < NearestDistance || NearestDistance == -1) { NearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < NearestDistance || NearestDistance == -1) { NearestDistance = hitInfo.distance; } } /* * if (Physics.Linecast(from, to + transform.forward * -Camera.main.nearClipPlane) && hitInfo.collider.tag != "Player") * { * if (hitInfo.distance < NearestDistance || NearestDistance == -1) * { * NearestDistance = hitInfo.distance; * } * }*/ return(NearestDistance); }
/// <summary> /// Checks whether the pivot point can see the camera and its near clip plane. /// </summary> /// <param name="from">The position of the pivot point.</param> /// <param name="to">The supposed position of the camera.</param> float CheckCameraPoints(Vector3 from, Vector3 to, Color color) { float nearestDistance = -1f; RaycastHit hitInfo; TP_Helper.ClipPlanePoints clipPlanePoints = TP_Helper.NearClipPlane(to, startingFOV); Vector3 bumperPoint = to + transform.forward * -Camera.main.nearClipPlane; // Draw lines to debug. Debug.DrawLine(from, bumperPoint, color); Debug.DrawLine(from, clipPlanePoints.lowerLeft, color); Debug.DrawLine(from, clipPlanePoints.lowerRight, color); Debug.DrawLine(from, clipPlanePoints.upperLeft, color); Debug.DrawLine(from, clipPlanePoints.upperRight, color); Debug.DrawLine(clipPlanePoints.upperLeft, clipPlanePoints.upperRight, color); Debug.DrawLine(clipPlanePoints.upperRight, clipPlanePoints.lowerRight, color); Debug.DrawLine(clipPlanePoints.lowerRight, clipPlanePoints.lowerLeft, color); Debug.DrawLine(clipPlanePoints.lowerLeft, clipPlanePoints.upperLeft, color); // LineCast to check whether the pivot point can see the near clip plane. if (Physics.Linecast(from, clipPlanePoints.upperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.lowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.upperRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.lowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, bumperPoint, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
void HandlePlayerInput() { float deadZone = 0.01f; //if (Input.GetMouseButton(1) == true) { mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity; mouseY += Input.GetAxis("Mouse Y") * -Y_MouseSensitivity; // min weghalen voor inverten //} mouseY = TP_Helper.ClampAngle(mouseY, Y_MinLimit, Y_MaxLimit); if (Input.GetAxis("Mouse ScrollWheel") < -deadZone || Input.GetAxis("Mouse ScrollWheel") > deadZone) { desiredDistance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity, distanceMin, distanceMax); _preOccludedDistance = desiredDistance; } }
void HandlePlayerInput() { float deadZone = 0.01f; mouseX += Input.GetAxis(horizontalAxis) * sensitivityX; if (!invertY) { mouseY -= Input.GetAxis(verticalAxis) * sensitivityY; } else { mouseY += Input.GetAxis(verticalAxis) * sensitivityY; } // Limit mouseY mouseY = TP_Helper.ClampAngle(mouseY, minLimitY, maxLimitY); if (Input.GetAxis(zoomAxis) < -deadZone || Input.GetAxis(zoomAxis) > deadZone) { desiredDistance = Mathf.Clamp(distance - Input.GetAxis(zoomAxis) * sensitivityZoom, distanceMin, distanceMax); } }