diff --git a/Assets/Scripts/Controllers/Generated/SimulatorControls.cs b/Assets/Scripts/Controllers/Generated/SimulatorControls.cs index a7481dc64..ddfb27e2c 100644 --- a/Assets/Scripts/Controllers/Generated/SimulatorControls.cs +++ b/Assets/Scripts/Controllers/Generated/SimulatorControls.cs @@ -19,6 +19,28 @@ public SimulatorControls() ""name"": ""Vehicle"", ""id"": ""eb4888fe-9130-4adc-a90b-bf846f8245e1"", ""actions"": [ + { + ""name"": ""ControllerSteering"", + ""id"": ""0f0f4029-be46-40fc-b132-611bd8141aec"", + ""expectedControlLayout"": ""Stick"", + ""continuous"": true, + ""passThrough"": true, + ""initialStateCheck"": false, + ""processors"": """", + ""interactions"": """", + ""bindings"": [] + }, + { + ""name"": ""ControllerAcceleration"", + ""id"": ""a1580238-3168-406e-a230-8c1594b9087f"", + ""expectedControlLayout"": ""Axis"", + ""continuous"": false, + ""passThrough"": false, + ""initialStateCheck"": false, + ""processors"": """", + ""interactions"": """", + ""bindings"": [] + }, { ""name"": ""Direction"", ""id"": ""74a3751d-7b46-43ea-8db5-6ff3c1a8a03d"", @@ -214,6 +236,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""875fed1c-0f90-4ee5-a7e7-1bbb47e113fb"", + ""path"": ""/buttonNorth"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""HeadLights"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""f071a7ab-903c-4f73-9277-245135e92351"", @@ -226,6 +260,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""5430d1d2-6cf4-4cb4-a986-4d572f8082f9"", + ""path"": ""/leftShoulder"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""IndicatorLeft"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""1c9be836-d82f-4f2f-b7fb-17cfc3ba4c42"", @@ -238,6 +284,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""b036930b-6827-456a-989c-f794dac39fcf"", + ""path"": ""/rightShoulder"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""IndicatorRight"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""102d8903-7ece-4382-8884-6ef9a3895b16"", @@ -274,6 +332,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""b3af9d0f-1716-41ac-909f-cc2d6390bc49"", + ""path"": ""/dpad/up"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""ShiftFirst"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""9f3653bb-d12f-464e-91a1-1e38d5432b7c"", @@ -286,6 +356,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""8675dfb7-a697-49e7-b6dc-cb9f821a784b"", + ""path"": ""/dpad/down"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""ShiftReverse"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""0b7bdefd-cff1-47e4-82a9-0a835e3d4539"", @@ -298,6 +380,18 @@ public SimulatorControls() ""isPartOfComposite"": false, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""5bbf6e96-bc8d-4ef0-9abe-654d1e1786e3"", + ""path"": ""/buttonSouth"", + ""interactions"": ""Press"", + ""processors"": """", + ""groups"": """", + ""action"": ""ParkingBrake"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""9b612607-638c-43ac-8787-e9a2df3ed7e6"", @@ -321,6 +415,54 @@ public SimulatorControls() ""isComposite"": false, ""isPartOfComposite"": false, ""modifiers"": """" + }, + { + ""name"": """", + ""id"": ""7574ccb9-ca8e-43a4-9792-8cae41bff976"", + ""path"": ""/leftStick"", + ""interactions"": """", + ""processors"": ""StickDeadzone(min=0.1)"", + ""groups"": """", + ""action"": ""ControllerSteering"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, + { + ""name"": ""Throttle_Brake"", + ""id"": ""7399bd92-679e-4f6a-9652-c7856003acf2"", + ""path"": ""1DAxis"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""ControllerAcceleration"", + ""isComposite"": true, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, + { + ""name"": ""negative"", + ""id"": ""769465d1-2550-4306-b97b-770804ff5a9c"", + ""path"": ""/leftTrigger"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""ControllerAcceleration"", + ""isComposite"": false, + ""isPartOfComposite"": true, + ""modifiers"": """" + }, + { + ""name"": ""positive"", + ""id"": ""56d9c3ba-b989-476b-b330-efde12b68b03"", + ""path"": ""/rightTrigger"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""ControllerAcceleration"", + ""isComposite"": false, + ""isPartOfComposite"": true, + ""modifiers"": """" } ] }, @@ -361,6 +503,17 @@ public SimulatorControls() ""interactions"": """", ""bindings"": [] }, + { + ""name"": ""GamepadView"", + ""id"": ""fbb8d49b-79f7-4673-908c-4941316a4138"", + ""expectedControlLayout"": ""Stick"", + ""continuous"": true, + ""passThrough"": false, + ""initialStateCheck"": true, + ""processors"": """", + ""interactions"": """", + ""bindings"": [] + }, { ""name"": ""MouseLeft"", ""id"": ""18683cc6-4aa4-44ca-9229-acb759267a4b"", @@ -449,6 +602,17 @@ public SimulatorControls() ""interactions"": """", ""bindings"": [] }, + { + ""name"": ""FlipCam"", + ""id"": ""b5b32f81-097a-40fc-91d4-7e965a377e3c"", + ""expectedControlLayout"": """", + ""continuous"": true, + ""passThrough"": true, + ""initialStateCheck"": false, + ""processors"": """", + ""interactions"": """", + ""bindings"": [] + }, { ""name"": ""CinematicNewPath"", ""id"": ""665b9005-f4bd-473b-9c46-4fd20642ac7d"", @@ -701,6 +865,30 @@ public SimulatorControls() ""isPartOfComposite"": true, ""modifiers"": """" }, + { + ""name"": """", + ""id"": ""7368c8b8-ecd6-4864-8a85-a0859a9da937"", + ""path"": ""/rightStick"", + ""interactions"": """", + ""processors"": ""StickDeadzone(min=0.1)"", + ""groups"": """", + ""action"": ""GamepadView"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, + { + ""name"": """", + ""id"": ""5e4b8691-a2f1-4fe3-b10e-046d9f8d376d"", + ""path"": ""/rightStickPress"", + ""interactions"": ""Hold(duration=0.01)"", + ""processors"": """", + ""groups"": """", + ""action"": ""FlipCam"", + ""isComposite"": false, + ""isPartOfComposite"": false, + ""modifiers"": """" + }, { ""name"": """", ""id"": ""12c41498-87d7-425f-968f-992e002859ea"", @@ -963,6 +1151,8 @@ public SimulatorControls() }"); // Vehicle m_Vehicle = asset.GetActionMap("Vehicle"); + m_Vehicle_ControllerSteering = m_Vehicle.GetAction("ControllerSteering"); + m_Vehicle_ControllerAcceleration = m_Vehicle.GetAction("ControllerAcceleration"); m_Vehicle_Direction = m_Vehicle.GetAction("Direction"); m_Vehicle_HeadLights = m_Vehicle.GetAction("HeadLights"); m_Vehicle_IndicatorLeft = m_Vehicle.GetAction("IndicatorLeft"); @@ -979,6 +1169,7 @@ public SimulatorControls() m_Camera_Direction = m_Camera.GetAction("Direction"); m_Camera_Elevation = m_Camera.GetAction("Elevation"); m_Camera_MouseDelta = m_Camera.GetAction("MouseDelta"); + m_Camera_GamepadView = m_Camera.GetAction("GamepadView"); m_Camera_MouseLeft = m_Camera.GetAction("MouseLeft"); m_Camera_MouseRight = m_Camera.GetAction("MouseRight"); m_Camera_MouseMiddle = m_Camera.GetAction("MouseMiddle"); @@ -987,6 +1178,7 @@ public SimulatorControls() m_Camera_Boost = m_Camera.GetAction("Boost"); m_Camera_ToggleState = m_Camera.GetAction("ToggleState"); m_Camera_Zoom = m_Camera.GetAction("Zoom"); + m_Camera_FlipCam = m_Camera.GetAction("FlipCam"); m_Camera_CinematicNewPath = m_Camera.GetAction("CinematicNewPath"); m_Camera_CinematicResetPath = m_Camera.GetAction("CinematicResetPath"); // Simulator @@ -1048,6 +1240,8 @@ public void Disable() // Vehicle private InputActionMap m_Vehicle; private IVehicleActions m_VehicleActionsCallbackInterface; + private InputAction m_Vehicle_ControllerSteering; + private InputAction m_Vehicle_ControllerAcceleration; private InputAction m_Vehicle_Direction; private InputAction m_Vehicle_HeadLights; private InputAction m_Vehicle_IndicatorLeft; @@ -1063,6 +1257,8 @@ public struct VehicleActions { private SimulatorControls m_Wrapper; public VehicleActions(SimulatorControls wrapper) { m_Wrapper = wrapper; } + public InputAction @ControllerSteering { get { return m_Wrapper.m_Vehicle_ControllerSteering; } } + public InputAction @ControllerAcceleration { get { return m_Wrapper.m_Vehicle_ControllerAcceleration; } } public InputAction @Direction { get { return m_Wrapper.m_Vehicle_Direction; } } public InputAction @HeadLights { get { return m_Wrapper.m_Vehicle_HeadLights; } } public InputAction @IndicatorLeft { get { return m_Wrapper.m_Vehicle_IndicatorLeft; } } @@ -1084,6 +1280,12 @@ public void SetCallbacks(IVehicleActions instance) { if (m_Wrapper.m_VehicleActionsCallbackInterface != null) { + ControllerSteering.started -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerSteering; + ControllerSteering.performed -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerSteering; + ControllerSteering.canceled -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerSteering; + ControllerAcceleration.started -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerAcceleration; + ControllerAcceleration.performed -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerAcceleration; + ControllerAcceleration.canceled -= m_Wrapper.m_VehicleActionsCallbackInterface.OnControllerAcceleration; Direction.started -= m_Wrapper.m_VehicleActionsCallbackInterface.OnDirection; Direction.performed -= m_Wrapper.m_VehicleActionsCallbackInterface.OnDirection; Direction.canceled -= m_Wrapper.m_VehicleActionsCallbackInterface.OnDirection; @@ -1121,6 +1323,12 @@ public void SetCallbacks(IVehicleActions instance) m_Wrapper.m_VehicleActionsCallbackInterface = instance; if (instance != null) { + ControllerSteering.started += instance.OnControllerSteering; + ControllerSteering.performed += instance.OnControllerSteering; + ControllerSteering.canceled += instance.OnControllerSteering; + ControllerAcceleration.started += instance.OnControllerAcceleration; + ControllerAcceleration.performed += instance.OnControllerAcceleration; + ControllerAcceleration.canceled += instance.OnControllerAcceleration; Direction.started += instance.OnDirection; Direction.performed += instance.OnDirection; Direction.canceled += instance.OnDirection; @@ -1171,6 +1379,7 @@ public VehicleActions @Vehicle private InputAction m_Camera_Direction; private InputAction m_Camera_Elevation; private InputAction m_Camera_MouseDelta; + private InputAction m_Camera_GamepadView; private InputAction m_Camera_MouseLeft; private InputAction m_Camera_MouseRight; private InputAction m_Camera_MouseMiddle; @@ -1179,6 +1388,7 @@ public VehicleActions @Vehicle private InputAction m_Camera_Boost; private InputAction m_Camera_ToggleState; private InputAction m_Camera_Zoom; + private InputAction m_Camera_FlipCam; private InputAction m_Camera_CinematicNewPath; private InputAction m_Camera_CinematicResetPath; public struct CameraActions @@ -1188,6 +1398,7 @@ public struct CameraActions public InputAction @Direction { get { return m_Wrapper.m_Camera_Direction; } } public InputAction @Elevation { get { return m_Wrapper.m_Camera_Elevation; } } public InputAction @MouseDelta { get { return m_Wrapper.m_Camera_MouseDelta; } } + public InputAction @GamepadView { get { return m_Wrapper.m_Camera_GamepadView; } } public InputAction @MouseLeft { get { return m_Wrapper.m_Camera_MouseLeft; } } public InputAction @MouseRight { get { return m_Wrapper.m_Camera_MouseRight; } } public InputAction @MouseMiddle { get { return m_Wrapper.m_Camera_MouseMiddle; } } @@ -1196,6 +1407,7 @@ public struct CameraActions public InputAction @Boost { get { return m_Wrapper.m_Camera_Boost; } } public InputAction @ToggleState { get { return m_Wrapper.m_Camera_ToggleState; } } public InputAction @Zoom { get { return m_Wrapper.m_Camera_Zoom; } } + public InputAction @FlipCam { get { return m_Wrapper.m_Camera_FlipCam; } } public InputAction @CinematicNewPath { get { return m_Wrapper.m_Camera_CinematicNewPath; } } public InputAction @CinematicResetPath { get { return m_Wrapper.m_Camera_CinematicResetPath; } } public InputActionMap Get() { return m_Wrapper.m_Camera; } @@ -1217,6 +1429,9 @@ public void SetCallbacks(ICameraActions instance) MouseDelta.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseDelta; MouseDelta.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseDelta; MouseDelta.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseDelta; + GamepadView.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnGamepadView; + GamepadView.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnGamepadView; + GamepadView.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnGamepadView; MouseLeft.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseLeft; MouseLeft.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseLeft; MouseLeft.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnMouseLeft; @@ -1241,6 +1456,9 @@ public void SetCallbacks(ICameraActions instance) Zoom.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnZoom; Zoom.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnZoom; Zoom.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnZoom; + FlipCam.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnFlipCam; + FlipCam.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnFlipCam; + FlipCam.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnFlipCam; CinematicNewPath.started -= m_Wrapper.m_CameraActionsCallbackInterface.OnCinematicNewPath; CinematicNewPath.performed -= m_Wrapper.m_CameraActionsCallbackInterface.OnCinematicNewPath; CinematicNewPath.canceled -= m_Wrapper.m_CameraActionsCallbackInterface.OnCinematicNewPath; @@ -1260,6 +1478,9 @@ public void SetCallbacks(ICameraActions instance) MouseDelta.started += instance.OnMouseDelta; MouseDelta.performed += instance.OnMouseDelta; MouseDelta.canceled += instance.OnMouseDelta; + GamepadView.started += instance.OnGamepadView; + GamepadView.performed += instance.OnGamepadView; + GamepadView.canceled += instance.OnGamepadView; MouseLeft.started += instance.OnMouseLeft; MouseLeft.performed += instance.OnMouseLeft; MouseLeft.canceled += instance.OnMouseLeft; @@ -1284,6 +1505,9 @@ public void SetCallbacks(ICameraActions instance) Zoom.started += instance.OnZoom; Zoom.performed += instance.OnZoom; Zoom.canceled += instance.OnZoom; + FlipCam.started += instance.OnFlipCam; + FlipCam.performed += instance.OnFlipCam; + FlipCam.canceled += instance.OnFlipCam; CinematicNewPath.started += instance.OnCinematicNewPath; CinematicNewPath.performed += instance.OnCinematicNewPath; CinematicNewPath.canceled += instance.OnCinematicNewPath; @@ -1374,6 +1598,8 @@ public SimulatorActions @Simulator } public interface IVehicleActions { + void OnControllerSteering(InputAction.CallbackContext context); + void OnControllerAcceleration(InputAction.CallbackContext context); void OnDirection(InputAction.CallbackContext context); void OnHeadLights(InputAction.CallbackContext context); void OnIndicatorLeft(InputAction.CallbackContext context); @@ -1391,6 +1617,7 @@ public interface ICameraActions void OnDirection(InputAction.CallbackContext context); void OnElevation(InputAction.CallbackContext context); void OnMouseDelta(InputAction.CallbackContext context); + void OnGamepadView(InputAction.CallbackContext context); void OnMouseLeft(InputAction.CallbackContext context); void OnMouseRight(InputAction.CallbackContext context); void OnMouseMiddle(InputAction.CallbackContext context); @@ -1399,6 +1626,7 @@ public interface ICameraActions void OnBoost(InputAction.CallbackContext context); void OnToggleState(InputAction.CallbackContext context); void OnZoom(InputAction.CallbackContext context); + void OnFlipCam(InputAction.CallbackContext context); void OnCinematicNewPath(InputAction.CallbackContext context); void OnCinematicResetPath(InputAction.CallbackContext context); } diff --git a/Assets/Scripts/Controllers/SimulatorCameraController.cs b/Assets/Scripts/Controllers/SimulatorCameraController.cs index ac4d74467..f1be50f83 100644 --- a/Assets/Scripts/Controllers/SimulatorCameraController.cs +++ b/Assets/Scripts/Controllers/SimulatorCameraController.cs @@ -51,6 +51,16 @@ public class SimulatorCameraController : MonoBehaviour private Vector3 cinematicEnd; private Vector3 cinematicOffset = new Vector3(0f, 10f, 0f); + public bool lockFreeCamRotationToVehicle = true; + private Vector2 gamepadViewInput; + private float camResetSpeed = 25f; + private float camLookTurnSpeed = 200.0f; + private float camTiltTurnSpeed = 200.0f; + private float camResetThreshold = 10.0f; + private Vector2 targetCamRotation = Vector2.zero; + public Rigidbody targetRB; + private bool camIsFlipped = false; + public CameraStateType CurrentCameraState = CameraStateType.Free; private void Awake() @@ -94,6 +104,13 @@ private void Awake() controls.Camera.MouseRight.performed += ctx => mouseRight = ctx.ReadValue(); controls.Camera.MouseRight.canceled += ctx => mouseRight = ctx.ReadValue(); + controls.Camera.GamepadView.started += ctx => gamepadViewInput = GetScaledLookInput(ctx.ReadValue()); + controls.Camera.GamepadView.performed += ctx => gamepadViewInput = GetScaledLookInput(ctx.ReadValue()); + controls.Camera.GamepadView.canceled += ctx => gamepadViewInput = Vector2.zero; + + controls.Camera.FlipCam.performed += ctx => camIsFlipped = true; + controls.Camera.FlipCam.canceled += ctx => camIsFlipped = false; + //controls.Camera.MouseMiddle.performed += ctx => ResetFollowRotation(); // TODO broken in package currently https://github.com/Unity-Technologies/InputSystem/issues/647 @@ -102,6 +119,11 @@ private void Awake() //controls.Camera.MouseScroll.canceled += ctx => mouseScroll = Vector2.zero; } + private Vector2 GetScaledLookInput(Vector2 rawLookInput) + { + return new Vector2(rawLookInput.x * camTiltTurnSpeed * Time.deltaTime, rawLookInput.y * camLookTurnSpeed * Time.deltaTime); + } + private void Start() { targetTiltFree = transform.eulerAngles.x; @@ -161,7 +183,14 @@ private void LateUpdate() UpdateFreeCamera(); break; case CameraStateType.Follow: - UpdateFollowCamera(); + if(lockFreeCamRotationToVehicle) + { + UpdateFollowLinkedRotationCamera(); + } + else + { + UpdateFollowCamera(); + } break; case CameraStateType.Cinematic: UpdateCinematicCamera(); @@ -221,6 +250,57 @@ private void UpdateFollowCamera() transform.position = Vector3.SmoothDamp(transform.position, targetObject.position, ref targetVelocity, 0.1f); } + private void UpdateFollowLinkedRotationCamera() + { + Debug.Assert(targetObject != null); + + var dist = Vector3.Distance(thisCamera.transform.position, targetObject.position); + if (dist < 3) + thisCamera.transform.localPosition = Vector3.MoveTowards(thisCamera.transform.localPosition, thisCamera.transform.InverseTransformPoint(targetObject.position), -Time.unscaledDeltaTime); + else if (dist > 30) + thisCamera.transform.localPosition = Vector3.MoveTowards(thisCamera.transform.localPosition, thisCamera.transform.InverseTransformPoint(targetObject.position), Time.unscaledDeltaTime); + else if (zoomInput != 0) + thisCamera.transform.localPosition = Vector3.MoveTowards(thisCamera.transform.localPosition, thisCamera.transform.InverseTransformPoint(targetObject.position), Time.unscaledDeltaTime * zoomInput * 10f * (boost == 1 ? 10f : 1f)); + + Vector2 viewInput = gamepadViewInput; + if (mouseRight == 1) + { + viewInput = mouseInput; + } + + if(targetCamRotation.y > 180.0f) + { + targetCamRotation.y -= 360.0f; + } + else if(targetCamRotation.y < -180.0f) + { + targetCamRotation.y += 360.0f; + } + + if(viewInput.sqrMagnitude <= 0.1 && targetRB != null && targetRB.velocity.sqrMagnitude > camResetThreshold) + { + targetCamRotation = Vector2.MoveTowards(targetCamRotation, Vector2.zero, Time.deltaTime * camResetSpeed); + } + else + { + targetCamRotation.y += viewInput.x * 0.25f; + targetCamRotation.x += viewInput.y * 0.1f * (inverted ? -1 : 1); + targetCamRotation.x = Mathf.Clamp(targetCamRotation.x, -15, 65); + } + + Quaternion targetQuat = Quaternion.LookRotation(camIsFlipped ? -targetObject.forward : targetObject.forward); + float tiltFree = targetCamRotation.x + targetQuat.eulerAngles.x; + float lookFree = targetCamRotation.y + targetQuat.eulerAngles.y; + + if (tiltFree > 180) + { + tiltFree -= 360; + } + + transform.rotation = Quaternion.Euler(tiltFree, lookFree, 0.0f); + transform.position = Vector3.SmoothDamp(transform.position, targetObject.position, ref targetVelocity, 0.1f); + } + private void UpdateCinematicCamera() { if (currentMapLane == null) @@ -307,6 +387,8 @@ public void SetFollowCameraState(GameObject target) targetTiltFree = transform.eulerAngles.x; targetLookFree = transform.eulerAngles.y; SimulatorManager.Instance.UIManager?.SetCameraButtonState(); + targetRB = target.GetComponent(); + targetCamRotation = transform.eulerAngles; } public void SetFreeCameraState() @@ -321,6 +403,8 @@ public void SetFreeCameraState() targetTiltFree = transform.eulerAngles.x; targetLookFree = transform.eulerAngles.y; SimulatorManager.Instance.UIManager?.SetCameraButtonState(); + targetRB = null; + targetCamRotation = transform.eulerAngles; } public void SetCinematicCameraState() diff --git a/Assets/Scripts/Controllers/SimulatorControls.inputactions b/Assets/Scripts/Controllers/SimulatorControls.inputactions index 40fe9c758..59dff3a3a 100644 --- a/Assets/Scripts/Controllers/SimulatorControls.inputactions +++ b/Assets/Scripts/Controllers/SimulatorControls.inputactions @@ -5,6 +5,28 @@ "name": "Vehicle", "id": "eb4888fe-9130-4adc-a90b-bf846f8245e1", "actions": [ + { + "name": "ControllerSteering", + "id": "0f0f4029-be46-40fc-b132-611bd8141aec", + "expectedControlLayout": "Stick", + "continuous": true, + "passThrough": true, + "initialStateCheck": false, + "processors": "", + "interactions": "", + "bindings": [] + }, + { + "name": "ControllerAcceleration", + "id": "a1580238-3168-406e-a230-8c1594b9087f", + "expectedControlLayout": "Axis", + "continuous": false, + "passThrough": false, + "initialStateCheck": false, + "processors": "", + "interactions": "", + "bindings": [] + }, { "name": "Direction", "id": "74a3751d-7b46-43ea-8db5-6ff3c1a8a03d", @@ -200,6 +222,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "875fed1c-0f90-4ee5-a7e7-1bbb47e113fb", + "path": "/buttonNorth", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "HeadLights", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "f071a7ab-903c-4f73-9277-245135e92351", @@ -212,6 +246,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "5430d1d2-6cf4-4cb4-a986-4d572f8082f9", + "path": "/leftShoulder", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "IndicatorLeft", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "1c9be836-d82f-4f2f-b7fb-17cfc3ba4c42", @@ -224,6 +270,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "b036930b-6827-456a-989c-f794dac39fcf", + "path": "/rightShoulder", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "IndicatorRight", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "102d8903-7ece-4382-8884-6ef9a3895b16", @@ -260,6 +318,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "b3af9d0f-1716-41ac-909f-cc2d6390bc49", + "path": "/dpad/up", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "ShiftFirst", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "9f3653bb-d12f-464e-91a1-1e38d5432b7c", @@ -272,6 +342,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "8675dfb7-a697-49e7-b6dc-cb9f821a784b", + "path": "/dpad/down", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "ShiftReverse", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "0b7bdefd-cff1-47e4-82a9-0a835e3d4539", @@ -284,6 +366,18 @@ "isPartOfComposite": false, "modifiers": "" }, + { + "name": "", + "id": "5bbf6e96-bc8d-4ef0-9abe-654d1e1786e3", + "path": "/buttonSouth", + "interactions": "Press", + "processors": "", + "groups": "", + "action": "ParkingBrake", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, { "name": "", "id": "9b612607-638c-43ac-8787-e9a2df3ed7e6", @@ -307,6 +401,54 @@ "isComposite": false, "isPartOfComposite": false, "modifiers": "" + }, + { + "name": "", + "id": "7574ccb9-ca8e-43a4-9792-8cae41bff976", + "path": "/leftStick", + "interactions": "", + "processors": "StickDeadzone(min=0.1)", + "groups": "", + "action": "ControllerSteering", + "isComposite": false, + "isPartOfComposite": false, + "modifiers": "" + }, + { + "name": "Throttle_Brake", + "id": "7399bd92-679e-4f6a-9652-c7856003acf2", + "path": "1DAxis", + "interactions": "", + "processors": "", + "groups": "", + "action": "ControllerAcceleration", + "isComposite": true, + "isPartOfComposite": false, + "modifiers": "" + }, + { + "name": "negative", + "id": "769465d1-2550-4306-b97b-770804ff5a9c", + "path": "/leftTrigger", + "interactions": "", + "processors": "", + "groups": "", + "action": "ControllerAcceleration", + "isComposite": false, + "isPartOfComposite": true, + "modifiers": "" + }, + { + "name": "positive", + "id": "56d9c3ba-b989-476b-b330-efde12b68b03", + "path": "/rightTrigger", + "interactions": "", + "processors": "", + "groups": "", + "action": "ControllerAcceleration", + "isComposite": false, + "isPartOfComposite": true, + "modifiers": "" } ] }, @@ -347,6 +489,17 @@ "interactions": "", "bindings": [] }, + { + "name": "GamepadView", + "id": "fbb8d49b-79f7-4673-908c-4941316a4138", + "expectedControlLayout": "Stick", + "continuous": true, + "passThrough": false, + "initialStateCheck": true, + "processors": "", + "interactions": "", + "bindings": [] + }, { "name": "MouseLeft", "id": "18683cc6-4aa4-44ca-9229-acb759267a4b", @@ -436,6 +589,13 @@ "bindings": [] }, { +<<<<<<< HEAD + "name": "FlipCam", + "id": "b5b32f81-097a-40fc-91d4-7e965a377e3c", + "expectedControlLayout": "", + "continuous": true, + "passThrough": true, +======= "name": "CinematicNewPath", "id": "665b9005-f4bd-473b-9c46-4fd20642ac7d", "expectedControlLayout": "Button", @@ -452,6 +612,7 @@ "expectedControlLayout": "Button", "continuous": false, "passThrough": false, +>>>>>>> dbf1704fc1def2d486500022ff38a6c2feca9fde "initialStateCheck": false, "processors": "", "interactions": "", @@ -689,24 +850,42 @@ }, { "name": "", +<<<<<<< HEAD + "id": "7368c8b8-ecd6-4864-8a85-a0859a9da937", + "path": "/rightStick", + "interactions": "", + "processors": "StickDeadzone(min=0.1)", + "groups": "", + "action": "GamepadView", +======= "id": "12c41498-87d7-425f-968f-992e002859ea", "path": "/#(C)", "interactions": "Press(behavior=1)", "processors": "", "groups": "", "action": "CinematicNewPath", +>>>>>>> dbf1704fc1def2d486500022ff38a6c2feca9fde "isComposite": false, "isPartOfComposite": false, "modifiers": "" }, { "name": "", +<<<<<<< HEAD + "id": "5e4b8691-a2f1-4fe3-b10e-046d9f8d376d", + "path": "/rightStickPress", + "interactions": "Hold(duration=0.01)", + "processors": "", + "groups": "", + "action": "FlipCam", +======= "id": "a7a9a91f-7fd6-4d86-8815-2efe6d2f2528", "path": "/#(V)", "interactions": "Press(behavior=1)", "processors": "", "groups": "", "action": "CinematicResetPath", +>>>>>>> dbf1704fc1def2d486500022ff38a6c2feca9fde "isComposite": false, "isPartOfComposite": false, "modifiers": "" diff --git a/Assets/Scripts/Sensors/ManualControlSensor.cs b/Assets/Scripts/Sensors/ManualControlSensor.cs index 0e02621fd..b171f1621 100644 --- a/Assets/Scripts/Sensors/ManualControlSensor.cs +++ b/Assets/Scripts/Sensors/ManualControlSensor.cs @@ -26,6 +26,8 @@ public class ManualControlSensor : SensorBase, IVehicleInputs AgentController AgentController; + private float steeringSpeed = 2.0f; + private void Start() { AgentController = GetComponentInParent(); @@ -58,6 +60,12 @@ private void Start() controls.Vehicle.IndicatorHazard.performed += IndicatorHazardPerformed; controls.Vehicle.FogLights.performed += FogLightsPerformed; controls.Vehicle.InteriorLight.performed += InteriorLightPerformed; + controls.Vehicle.ControllerSteering.started += ControllerSteeringStarted; + controls.Vehicle.ControllerSteering.performed += ControllerSteeringPerformed; + controls.Vehicle.ControllerSteering.canceled += ControllerSteeringCanceled; + controls.Vehicle.ControllerAcceleration.started += ControllerAccelerationStarted; + controls.Vehicle.ControllerAcceleration.performed += ControllerAccelerationPerformed; + controls.Vehicle.ControllerAcceleration.canceled += ControllerAccelerationCanceled; } } @@ -126,6 +134,36 @@ private void InteriorLightPerformed(UnityEngine.InputSystem.InputAction.Callback actions.InteriorLight = !actions.InteriorLight; } + private void ControllerSteeringStarted(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.x = obj.ReadValue().x; + } + + private void ControllerSteeringPerformed(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.x = obj.ReadValue().x; + } + + private void ControllerSteeringCanceled(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.x = 0.0f; + } + + private void ControllerAccelerationStarted(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.y = obj.ReadValue(); + } + + private void ControllerAccelerationPerformed(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.y = obj.ReadValue(); + } + + private void ControllerAccelerationCanceled(UnityEngine.InputSystem.InputAction.CallbackContext obj) + { + keyboardInput.y = 0.0f; + } + private void Update() { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor) @@ -154,7 +192,7 @@ private void Update() if (AgentController.Active) { - SteerInput = Mathf.MoveTowards(SteerInput, keyboardInput.x, Time.deltaTime); + SteerInput = Mathf.MoveTowards(SteerInput, keyboardInput.x, Time.deltaTime * steeringSpeed); AccelInput = keyboardInput.y; } } @@ -180,6 +218,12 @@ private void OnDestroy() controls.Vehicle.IndicatorHazard.performed -= IndicatorHazardPerformed; controls.Vehicle.FogLights.performed -= FogLightsPerformed; controls.Vehicle.InteriorLight.performed -= InteriorLightPerformed; + controls.Vehicle.ControllerSteering.started -= ControllerSteeringStarted; + controls.Vehicle.ControllerSteering.performed -= ControllerSteeringPerformed; + controls.Vehicle.ControllerSteering.canceled -= ControllerSteeringCanceled; + controls.Vehicle.ControllerAcceleration.started -= ControllerAccelerationStarted; + controls.Vehicle.ControllerAcceleration.performed -= ControllerAccelerationPerformed; + controls.Vehicle.ControllerAcceleration.canceled -= ControllerAccelerationCanceled; } }