public void FixedUpdate() { if (isDazzling) { currentFOV = Mathf.Lerp(currentFOV, userFOV, 0.04f); currentDistance = Mathf.Lerp(currentDistance, userDistance, 0.04f); mainCam.SetFoV(currentFOV); mainCam.SetDistance(currentDistance); print("Distance: " + currentDistance); if (userFOV + 0.25 >= currentFOV) { mainCam.SetFoV(userFOV); mainCam.SetDistance(userDistance); print("Done messing with camera!"); isDazzling = false; } } }
public void cameraRotationCallback(byte ID, object Data) { //Debug.Log("Camera Rotation Callback"); newCameraRotation = KerbalSimpitUtils.ByteArrayToStructure <CameraRotationalStruct>((byte[])Data); // Bit fields: // pitch = 1 // roll = 2 // yaw = 4 switch (cameraManager.currentCameraMode) { case CameraManager.CameraMode.Flight: FlightCamera flightCamera = FlightCamera.fetch; if ((newCameraRotation.mask & (byte)1) > 0) { myCameraRotation.pitch = newCameraRotation.pitch; // Debug.Log("Rotation Message Seen"); float newPitch = flightCamera.camPitch + (myCameraRotation.pitch * flightCameraPitchMultiplier); if (newPitch > flightCamera.maxPitch) { flightCamera.camPitch = flightCamera.maxPitch; } else if (newPitch < flightCamera.minPitch) { flightCamera.camPitch = flightCamera.minPitch; } else { flightCamera.camPitch = newPitch; } } if ((newCameraRotation.mask & (byte)2) > 0) { myCameraRotation.roll = newCameraRotation.roll; } if ((newCameraRotation.mask & (byte)4) > 0) { myCameraRotation.yaw = newCameraRotation.yaw; // Debug.Log("Yaw Message Seen"); float newHdg = flightCamera.camHdg + (myCameraRotation.yaw * flightCameraYawMultiplier); flightCamera.camHdg = newHdg; } if ((newCameraRotation.mask & (byte)8) > 0) { myCameraRotation.zoom = newCameraRotation.zoom; float newZoom = flightCamera.Distance + (myCameraRotation.zoom * flightCameraZoomMultiplier); if (newZoom > flightCamera.maxDistance) { newZoom = flightCamera.maxDistance; } else if (newZoom < flightCamera.minDistance) { newZoom = flightCamera.minDistance; } flightCamera.SetDistance(newZoom); } break; case CameraManager.CameraMode.IVA: case CameraManager.CameraMode.Internal: Kerbal ivaKerbal = cameraManager.IVACameraActiveKerbal; if (ivaKerbal == null) { Debug.Log("Kerbal is null"); } InternalCamera ivaCamera = InternalCamera.Instance; ivaCamera.mouseLocked = false; if (ivaCamera == null) { Debug.Log("IVA Camera is null"); } else { float newPitch = (float)ivaPitchField.GetValue(ivaCamera); float newYaw = (float)ivaYawField.GetValue(ivaCamera); if ((newCameraRotation.mask & (byte)1) > 0) { myCameraRotation.pitch = newCameraRotation.pitch; //Debug.Log("IVA Rotation Message Seen"); newPitch += (myCameraRotation.pitch * ivaCameraMultiplier); if (newPitch > ivaCamera.maxPitch) { newPitch = ivaCamera.maxPitch; } else if (newPitch < ivaCamera.minPitch) { newPitch = ivaCamera.minPitch; } } if ((newCameraRotation.mask & (byte)2) > 0) { myCameraRotation.roll = newCameraRotation.roll; } if ((newCameraRotation.mask & (byte)4) > 0) { myCameraRotation.yaw = newCameraRotation.yaw; //Debug.Log("IVA Yaw Message Seen"); newYaw += (myCameraRotation.yaw * ivaCameraMultiplier); if (newYaw > 120f) { newYaw = 120f; } else if (newYaw < -120f) { newYaw = -120f; } } //Debug.Log("Before set angle"); if (this.ivaCamFieldsLoaded) { ivaPitchField.SetValue(ivaCamera, newPitch); ivaYawField.SetValue(ivaCamera, newYaw); // Debug.Log("Camera vector: " + ivaCamera.transform.localEulerAngles.ToString()); FlightCamera.fetch.transform.rotation = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.rotation); } } break; default: Debug.Log("Kerbal Simpit does not support this camera mode: " + cameraManager.currentCameraMode.ToString()); break; } }