commit 60b19ae881e9c443ca11922056a9293eebd159c7 parent 5205c4232d59ea11b44418d3617a754cca7b0fac Author: PlutoTank <qwolkensperg@gmail.com> Date: Fri, 17 Apr 2020 18:07:26 -0400 Smoothed input swords added Diffstat:
17 files changed, 159 insertions(+), 125 deletions(-)
diff --git a/Assets/Prefabs/Slimes/Slime.prefab b/Assets/Prefabs/Slimes/Slime.prefab @@ -948,8 +948,8 @@ GameObject: - component: {fileID: 5435084252436152422} - component: {fileID: 1963935554026982} - component: {fileID: 528797603923251975} - - component: {fileID: 1450437300} - component: {fileID: 3959615095757466810} + - component: {fileID: 1450437300} - component: {fileID: 1545482344972484104} m_Layer: 9 m_Name: Slime @@ -1124,6 +1124,25 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _characterMovementController: {fileID: 1533019556350475861} +--- !u!114 &3959615095757466810 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1531394410883810673} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6f7780a3c04e17841825f68a82642af4, type: 3} + m_Name: + m_EditorClassIdentifier: + defaultOrbitalLogic: {fileID: 11400000, guid: f604a09f73d9b3e4a8d515810e94c6d9, + type: 2} + orbitals: + - orbital: {fileID: 2311679785310360297, guid: 4e346bd7fa8310847b295522d78bb540, + type: 3} + orbitalLogic: {fileID: 11400000, guid: e77fb33472e993c4fbd1004f42fc4ed2, type: 2} + sticky: 0 --- !u!114 &1450437300 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1197,25 +1216,6 @@ MonoBehaviour: m_DefaultActionMap: VsGameplay m_SplitScreenIndex: -1 m_Camera: {fileID: 0} ---- !u!114 &3959615095757466810 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1531394410883810673} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6f7780a3c04e17841825f68a82642af4, type: 3} - m_Name: - m_EditorClassIdentifier: - defaultOrbitalLogic: {fileID: 11400000, guid: f604a09f73d9b3e4a8d515810e94c6d9, - type: 2} - orbitals: - - orbital: {fileID: 2311679785310360297, guid: 4e346bd7fa8310847b295522d78bb540, - type: 3} - orbitalLogic: {fileID: 11400000, guid: e77fb33472e993c4fbd1004f42fc4ed2, type: 2} - sticky: 0 --- !u!82 &1545482344972484104 AudioSource: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Slimecing/InputSystem/SlimeControls.cs b/Assets/Scripts/Slimecing/InputSystem/SlimeControls.cs @@ -256,14 +256,25 @@ namespace Slimecing.InputSystem ""bindings"": [ { ""name"": """", - ""id"": ""399b431c-036d-4e1c-ba97-02388adf41a7"", + ""id"": ""ca69d397-54f1-4ea7-a580-7773a6e6f0a6"", ""path"": ""<Gamepad>/rightStick"", ""interactions"": """", - ""processors"": ""NormalizeVector2,StickDeadzone"", + ""processors"": """", ""groups"": ""Gamepad"", ""action"": ""SwordMovement"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""1e69138a-f920-40c8-a4bc-4ff87648ceab"", + ""path"": ""<Mouse>/position"", + ""interactions"": """", + ""processors"": ""NormalizeVector2"", + ""groups"": ""Keyboard & Mouse"", + ""action"": ""SwordMovement"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] } diff --git a/Assets/Scripts/Slimecing/InputSystem/SlimeControls.inputactions b/Assets/Scripts/Slimecing/InputSystem/SlimeControls.inputactions @@ -241,14 +241,25 @@ "bindings": [ { "name": "", - "id": "399b431c-036d-4e1c-ba97-02388adf41a7", + "id": "ca69d397-54f1-4ea7-a580-7773a6e6f0a6", "path": "<Gamepad>/rightStick", "interactions": "", - "processors": "NormalizeVector2,StickDeadzone", + "processors": "", "groups": "Gamepad", "action": "SwordMovement", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "1e69138a-f920-40c8-a4bc-4ff87648ceab", + "path": "<Mouse>/position", + "interactions": "", + "processors": "NormalizeVector2", + "groups": "Keyboard & Mouse", + "action": "SwordMovement", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/IOrbitalTickEveryFrame.cs.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/IOrbitalTickEveryFrame.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cda308dbd2e7b064a984cf6e203a7535 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogic.cs @@ -35,7 +35,7 @@ namespace Slimecing.Swords.Orbitals } public abstract void Initialize(GameObject owner, GameObject orbital); - + public abstract void Tick(GameObject owner, GameObject orbital); } } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs @@ -1,4 +1,4 @@ -using System; +using System; using Slimecing.Dependency; using Slimecing.Triggers; using UnityEngine; @@ -6,40 +6,45 @@ using UnityEngine; namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts { [CreateAssetMenu(fileName = "InputOrbitalLogic", menuName = "Swords/Orbitals/OrbitalLogic/InputOrbitalLogic")] - public class InputOrbitalLogic : OrbitalLogic + public class InputOrbitalLogic : OrbitalLogic, IOrbitalTickEveryFrame { [SerializeField] private Trigger orbitalInputTrigger; - private Vector2 _pointPos; - private Vector3 _center; - private Vector3 _finalSwordTarget; + private Trigger _operatingOrbitalInputTrigger; + private Ellipse _swordEllipse; + private Vector2 _finalSwordTarget; - private TriggerInput GetInputAbilityActionType() + private void OnEnable() { - if (orbitalInputTrigger == null) return null; - return orbitalInputTrigger as TriggerInput; + _swordEllipse = new Ellipse(XAxis, ZAxis); + _operatingOrbitalInputTrigger = Instantiate(orbitalInputTrigger); } - public override void Initialize(GameObject owner, GameObject orbital) + private TriggerInput GetInputAbilityActionType() { - _center = owner.transform.position; - GetInput(orbital, Vector2.up); - GetInputAbilityActionType()?.ConfigureInput(owner); - orbitalInputTrigger.TriggerStateChange += trigger => UpdateOrbitalPos(owner, orbital, trigger); + if (_operatingOrbitalInputTrigger == null) return null; + return _operatingOrbitalInputTrigger as TriggerInput; } - private void UpdateOrbitalPos(GameObject owner, GameObject orbital, TriggerPackage trigger) + public override void Initialize(GameObject owner, GameObject orbital) { - if (!trigger.user.Equals(owner)) return; - - GetInput(orbital, trigger.ctx.ReadValue<Vector2>()); + GetInput(owner, orbital, Vector2.up); + GetInputAbilityActionType()?.ConfigureInput(owner); } public override void Tick(GameObject owner, GameObject orbital) { - _center = owner.transform.position; - - orbital.transform.position = _finalSwordTarget + _center; + Vector3 center = owner.transform.position; + + float step = Time.fixedDeltaTime * RotSpeed; + Vector2 circlePos = _swordEllipse.EvaluateEllipse(_finalSwordTarget.x); + Vector3 targetPos = new Vector3(circlePos.x, YOffset, circlePos.y); + Vector3 smoothPos = Vector3.RotateTowards(orbital.transform.position - center, targetPos, step, 0f); + Vector3 orbitPos = new Vector3(smoothPos.normalized.x * XAxis, YOffset, smoothPos.normalized.z * ZAxis); + if (orbitPos != orbital.transform.position) + { + orbital.transform.position = orbitPos + center; + } SetLook(owner, orbital); } @@ -51,18 +56,26 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts orbital.transform.LookAt(2 * position - new Vector3(ownerPos.x, position.y, ownerPos.z)); } - private void GetInput(GameObject orbital, Vector2 inputDir) + private void GetInput(GameObject owner, GameObject orbital, Vector2 inputDir) + { + if (inputDir.Equals(Vector2.zero)) return; + if (!(Mathf.Abs(inputDir.x) > 0.05f) && !(Mathf.Abs(inputDir.y) > 0.05f)) return; + Vector3 center = owner.transform.position; + float pointX = inputDir.x; + float pointZ = inputDir.y; + float angle = Mathf.Atan2(pointX, pointZ) * Mathf.Rad2Deg; + var position = orbital.transform.position; + float currentAngle = Mathf.Atan2(position.x - center.x,position.z - center.z) * Mathf.Rad2Deg; + _finalSwordTarget = new Vector2(angle / 360f, currentAngle / 360f); + } + + public void TickUpdate(GameObject owner, GameObject orbital) { - if (!(Mathf.Abs(inputDir.x) > 0.5) && !(Mathf.Abs(inputDir.y) > 0.5)) return; - float pointX = XAxis * inputDir.x; - float pointZ = ZAxis * inputDir.y; - _pointPos = new Vector2(pointX, pointZ); - Vector3 targetPos = new Vector3(_pointPos.x, YOffset, _pointPos.y); - /*Vector3 swordTarget = Vector3.RotateTowards(orbital.transform.position - _center, - targetPos - _center, Time.deltaTime * RotSpeed, 0f); - Vector3 swordTargetNormalized = swordTarget.normalized;*/ - //_finalSwordTarget = new Vector3(swordTargetNormalized.x * XAxis, YOffset, swordTargetNormalized.z * ZAxis); - _finalSwordTarget = targetPos; + if (!_operatingOrbitalInputTrigger.currentTriggerState.Equals(TriggerState.Performed)) return; + if (_operatingOrbitalInputTrigger is TriggerInput orbitalTriggerInput) + { + GetInput(owner, orbital, orbitalTriggerInput.inputContext.ReadValue<Vector2>()); + } } } -} +}+ \ No newline at end of file diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/TimerOrbitalLogic.cs @@ -52,7 +52,7 @@ namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts private void Rotate(GameObject owner, GameObject orbital) { float orbitSpeed = 1f / RotSpeed; - orbitalProgress += Time.deltaTime * orbitSpeed; + orbitalProgress += Time.fixedDeltaTime * orbitSpeed; orbitalProgress %= 1f; SetOrbitalPos(owner, orbital); } diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset @@ -12,9 +12,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5d7968acda84baa4fa1a7008b6f01265, type: 3} m_Name: InputOrbitalLogic m_EditorClassIdentifier: - rotSpeed: 60 + rotSpeed: 10 yOffset: 1 - xAxis: 2.2 - zAxis: 2.2 - orbitalInputTrigger: {fileID: 11400000, guid: 4c7d44de3d4eecc438c60d97a9a2874b, + xAxis: 2.5 + zAxis: 2.5 + orbitalInputTrigger: {fileID: 11400000, guid: 8e538a3d690d3d446aaf393f3d8319f3, type: 2} diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/TakesOrbitals.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/TakesOrbitals.cs @@ -1,5 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Slimecing.Swords.DropBehaviour; +using Slimecing.Swords.Orbitals.OrbitalLogicScripts; +using Slimecing.Triggers; using UnityEngine; namespace Slimecing.Swords.Orbitals @@ -100,6 +103,17 @@ namespace Slimecing.Swords.Orbitals public void Update() { + foreach (var orbital in orbitals) + { + if (orbital.OrbitalLogic is IOrbitalTickEveryFrame inputOrbitalLogic) + { + inputOrbitalLogic.TickUpdate(gameObject, orbital.orbitalObject); + } + } + } + + public void FixedUpdate() + { ValidateOrbitals(); foreach (var orbital in orbitals) diff --git a/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset b/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset @@ -1,16 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b724fbf88219cb4459211c90795c6464, type: 3} - m_Name: AxisInputTrigger - m_EditorClassIdentifier: - inputActionReference: {fileID: -2472351366228085227, guid: e5353b3c2a300ce458b25d1e62215e9c, - type: 3} diff --git a/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset.meta b/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset.meta @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4c7d44de3d4eecc438c60d97a9a2874b -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs b/Assets/Scripts/Slimecing/Triggers/TriggerInput.cs @@ -7,6 +7,8 @@ namespace Slimecing.Triggers { [SerializeField] private InputActionReference inputActionReference; + public InputAction.CallbackContext inputContext { get; set; } + public InputActionReference currentActionReference { get => inputActionReference; set => inputActionReference = value; } public PlayerInput currentPlayerInput { get; set; } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs @@ -1,27 +0,0 @@ -using UnityEngine; -using UnityEngine.InputSystem; - -namespace Slimecing.Triggers.TriggerLogic -{ - [CreateAssetMenu(fileName = "AxisInputTrigger ", menuName = "Triggers/InputTriggers/AxisInputTrigger ")] - public class AxisInputTrigger : TriggerInput - { - protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) - { - currentTriggerState = TriggerState.Performed; - OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); - } - - protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx) - { - currentTriggerState = TriggerState.Performed; - OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); - } - - protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) - { - currentTriggerState = TriggerState.Canceled; - OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); - } - } -} diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs.meta b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs.meta @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b724fbf88219cb4459211c90795c6464 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTriggerPolling.cs @@ -0,0 +1,28 @@ +using UnityEngine; +using UnityEngine.InputSystem; + +namespace Slimecing.Triggers.TriggerLogic +{ + [CreateAssetMenu(fileName = "AxisInputTrigger ", menuName = "Triggers/InputTriggers/AxisInputTrigger ")] + public class AxisInputTrigger : TriggerInput + { + protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) + { + + } + + protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx) + { + currentTriggerState = TriggerState.Performed; + inputContext = ctx; + OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); + } + + protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) + { + currentTriggerState = TriggerState.Canceled; + inputContext = ctx; + OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); + } + } +} diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/HoldButtonInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/HoldButtonInputTrigger.cs @@ -9,18 +9,21 @@ namespace Slimecing.Triggers.TriggerLogic protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) { currentTriggerState = TriggerState.Started; + inputContext = ctx; OnTriggerStateChange(new TriggerPackage(TriggerState.Started, player, ctx)); } protected override void TriggerPerformed(GameObject player, InputAction.CallbackContext ctx) { currentTriggerState = TriggerState.Performed; + inputContext = ctx; OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); } protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) { currentTriggerState = TriggerState.Canceled; + inputContext = ctx; OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); } } diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/SimpleButtonInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/SimpleButtonInputTrigger.cs @@ -9,6 +9,7 @@ namespace Slimecing.Triggers.TriggerLogic protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx) { currentTriggerState = TriggerState.Performed; + inputContext = ctx; OnTriggerStateChange(new TriggerPackage(TriggerState.Performed, player, ctx)); } @@ -17,6 +18,7 @@ namespace Slimecing.Triggers.TriggerLogic protected override void TriggerCanceled(GameObject player, InputAction.CallbackContext ctx) { currentTriggerState = TriggerState.Canceled; + inputContext = ctx; OnTriggerStateChange(new TriggerPackage(TriggerState.Canceled, player, ctx)); } }