From 07bb4671cd73642321bab48714c3e23fbb6e7efd Mon Sep 17 00:00:00 2001 From: Dale Eidd Date: Tue, 26 Oct 2021 16:26:08 -0700 Subject: [PATCH 1/2] Fix boat inputs not working for 2021.2 We did not respect the "update mode" setting but it worked before 2021.2 for some reason. Input in "update" looks to be the default so this will cover us for now. --- .../BoatDev/Scripts/BoatAlignNormal.cs | 57 ++++++++++++++----- .../Crest/Scripts/Interaction/BoatProbes.cs | 51 +++++++++++------ 2 files changed, 78 insertions(+), 30 deletions(-) diff --git a/crest/Assets/Crest/Crest-Examples/BoatDev/Scripts/BoatAlignNormal.cs b/crest/Assets/Crest/Crest-Examples/BoatDev/Scripts/BoatAlignNormal.cs index 5a37a1945..abc870383 100644 --- a/crest/Assets/Crest/Crest-Examples/BoatDev/Scripts/BoatAlignNormal.cs +++ b/crest/Assets/Crest/Crest-Examples/BoatDev/Scripts/BoatAlignNormal.cs @@ -76,6 +76,9 @@ public class BoatAlignNormal : FloatingObjectBase SampleHeightHelper _sampleHeightHelperLengthwise = new SampleHeightHelper(); SampleFlowHelper _sampleFlowHelper = new SampleFlowHelper(); + float _inputForward; + float _inputSideward; + void Start() { _rb = GetComponent(); @@ -87,6 +90,37 @@ void Start() } } +#if ENABLE_INPUT_SYSTEM + void Update() + { + if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate) + { + UpdateInput(); + } + } +#endif + + void UpdateInput() + { +#if ENABLE_INPUT_SYSTEM + _inputForward = !Application.isFocused ? 0 : + ((Keyboard.current.wKey.isPressed ? 1 : 0) + (Keyboard.current.sKey.isPressed ? -1 : 0)); +#else + _inputForward = Input.GetAxis("Vertical"); +#endif + var reverseMultiplier = _inputForward < 0f ? -1f : 1f; + +#if ENABLE_INPUT_SYSTEM + _inputSideward = !Application.isFocused ? 0 : + ((Keyboard.current.aKey.isPressed ? reverseMultiplier * -1f : 0f) + + (Keyboard.current.dKey.isPressed ? reverseMultiplier * 1f : 0f)); +#else + _inputSideward = + (Input.GetKey(KeyCode.A) ? reverseMultiplier * -1f : 0f) + + (Input.GetKey(KeyCode.D) ? reverseMultiplier * 1f : 0f); +#endif + } + void FixedUpdate() { if (OceanRenderer.Instance == null) @@ -146,26 +180,21 @@ void FixedUpdate() _rb.AddForceAtPosition(transform.right * Vector3.Dot(transform.right, -velocityRelativeToWater) * _dragInWaterRight, forcePosition, ForceMode.Acceleration); _rb.AddForceAtPosition(transform.forward * Vector3.Dot(transform.forward, -velocityRelativeToWater) * _dragInWaterForward, forcePosition, ForceMode.Acceleration); - float forward = _throttleBias; #if ENABLE_INPUT_SYSTEM - float rawForward = !Application.isFocused ? 0 : ((Keyboard.current.wKey.isPressed ? 1 : 0) + (Keyboard.current.sKey.isPressed ? -1 : 0)); + if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInFixedUpdate) + { + UpdateInput(); + } #else - float rawForward = Input.GetAxis("Vertical"); + UpdateInput(); #endif - if (_playerControlled) forward += rawForward; + + float forward = _throttleBias; + if (_playerControlled) forward += _inputForward; _rb.AddForceAtPosition(transform.forward * _enginePower * forward, forcePosition, ForceMode.Acceleration); - float reverseMultiplier = (rawForward < 0f ? -1f : 1f); float sideways = _steerBias; - if (_playerControlled) sideways += -#if ENABLE_INPUT_SYSTEM - !Application.isFocused ? 0 : - ((Keyboard.current.aKey.isPressed ? reverseMultiplier * -1f : 0f) + - (Keyboard.current.dKey.isPressed ? reverseMultiplier * 1f : 0f)); -#else - (Input.GetKey(KeyCode.A) ? reverseMultiplier * -1f : 0f) + - (Input.GetKey(KeyCode.D) ? reverseMultiplier * 1f : 0f); -#endif + if (_playerControlled) sideways += _inputSideward; _rb.AddTorque(transform.up * _turnPower * sideways, ForceMode.Acceleration); FixedUpdateOrientation(normal); diff --git a/crest/Assets/Crest/Crest/Scripts/Interaction/BoatProbes.cs b/crest/Assets/Crest/Crest/Scripts/Interaction/BoatProbes.cs index 4568c1f39..9e6873fbd 100644 --- a/crest/Assets/Crest/Crest/Scripts/Interaction/BoatProbes.cs +++ b/crest/Assets/Crest/Crest/Scripts/Interaction/BoatProbes.cs @@ -74,6 +74,9 @@ public class BoatProbes : FloatingObjectBase SampleFlowHelper _sampleFlowHelper = new SampleFlowHelper(); + float _inputForward; + float _inputSideward; + private void Start() { _rb = GetComponent(); @@ -92,6 +95,36 @@ private void Start() _queryResultVels = new Vector3[_forcePoints.Length + 1]; } +#if ENABLE_INPUT_SYSTEM + void Update() + { + if (InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsInDynamicUpdate) + { + UpdateInput(); + } + } +#endif + + void UpdateInput() + { +#if ENABLE_INPUT_SYSTEM + _inputForward = !Application.isFocused ? 0 : + ((Keyboard.current.wKey.isPressed ? 1 : 0) + (Keyboard.current.sKey.isPressed ? -1 : 0)); +#else + _inputForward = Input.GetAxis("Vertical"); +#endif + +#if ENABLE_INPUT_SYSTEM + _inputSideward = !Application.isFocused ? 0 : + ((Keyboard.current.aKey.isPressed ? -1f : 0f) + + (Keyboard.current.dKey.isPressed ? 1f : 0f)); +#else + _inputSideward = + (Input.GetKey(KeyCode.A) ? -1f : 0f) + + (Input.GetKey(KeyCode.D) ? 1f : 0f); +#endif + } + void CalcTotalWeight() { _totalWeight = 0f; @@ -152,25 +185,11 @@ void FixedUpdateEngine() var forcePosition = _rb.position; var forward = _engineBias; - if (_playerControlled) forward += -#if ENABLE_INPUT_SYSTEM - !Application.isFocused ? 0 : - ((Keyboard.current.wKey.isPressed ? 1 : 0) + (Keyboard.current.sKey.isPressed ? -1 : 0)); -#else - Input.GetAxis("Vertical"); -#endif + if (_playerControlled) forward += _inputForward; _rb.AddForceAtPosition(transform.forward * _enginePower * forward, forcePosition, ForceMode.Acceleration); var sideways = _turnBias; - if (_playerControlled) sideways += -#if ENABLE_INPUT_SYSTEM - !Application.isFocused ? 0 : - ((Keyboard.current.aKey.isPressed ? -1f : 0f) + - (Keyboard.current.dKey.isPressed ? 1f : 0f)); -#else - (Input.GetKey(KeyCode.A) ? -1f : 0f) + - (Input.GetKey(KeyCode.D) ? 1f : 0f); -#endif + if (_playerControlled) sideways += _inputSideward; var rotVec = transform.up + _turningHeel * transform.forward; _rb.AddTorque(rotVec * _turnPower * sideways, ForceMode.Acceleration); } From 70fb192782b7f6d759b3cb6a2da72dcd620a4b95 Mon Sep 17 00:00:00 2001 From: Dale Eidd Date: Tue, 26 Oct 2021 16:32:13 -0700 Subject: [PATCH 2/2] Docs: update history --- docs/about/history.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/about/history.rst b/docs/about/history.rst index 35a7a1a79..ed9dd6448 100644 --- a/docs/about/history.rst +++ b/docs/about/history.rst @@ -47,6 +47,7 @@ Fixed - Fix FFT spectrum not being editable when time is paused. - Fix *ShapeFFT* component producing inverted looking waves when enabled in editor play mode. - Fix SSS colour missing or popping in the distance. + - Fix boat components not responding to user input for 2021. .. only:: birp