commit 5205c4232d59ea11b44418d3617a754cca7b0fac
parent 524414c1bc8a62d75715abbc474b0c07346c191e
Author: PlutoTank <qwolkensperg@gmail.com>
Date: Thu, 16 Apr 2020 21:56:00 -0400
small orbital bug fix
Diffstat:
7 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs b/Assets/Scripts/Slimecing/Swords/Orbitals/OrbitalLogicScripts/InputOrbitalLogic.cs
@@ -0,0 +1,68 @@
+using System;
+using Slimecing.Dependency;
+using Slimecing.Triggers;
+using UnityEngine;
+
+namespace Slimecing.Swords.Orbitals.OrbitalLogicScripts
+{
+ [CreateAssetMenu(fileName = "InputOrbitalLogic", menuName = "Swords/Orbitals/OrbitalLogic/InputOrbitalLogic")]
+ public class InputOrbitalLogic : OrbitalLogic
+ {
+ [SerializeField] private Trigger orbitalInputTrigger;
+
+ private Vector2 _pointPos;
+ private Vector3 _center;
+ private Vector3 _finalSwordTarget;
+
+ private TriggerInput GetInputAbilityActionType()
+ {
+ if (orbitalInputTrigger == null) return null;
+ return orbitalInputTrigger as TriggerInput;
+ }
+
+ public override void Initialize(GameObject owner, GameObject orbital)
+ {
+ _center = owner.transform.position;
+ GetInput(orbital, Vector2.up);
+ GetInputAbilityActionType()?.ConfigureInput(owner);
+ orbitalInputTrigger.TriggerStateChange += trigger => UpdateOrbitalPos(owner, orbital, trigger);
+ }
+
+ private void UpdateOrbitalPos(GameObject owner, GameObject orbital, TriggerPackage trigger)
+ {
+ if (!trigger.user.Equals(owner)) return;
+
+ GetInput(orbital, trigger.ctx.ReadValue<Vector2>());
+ }
+
+ public override void Tick(GameObject owner, GameObject orbital)
+ {
+ _center = owner.transform.position;
+
+ orbital.transform.position = _finalSwordTarget + _center;
+
+ SetLook(owner, orbital);
+ }
+
+ private void SetLook(GameObject owner, GameObject orbital)
+ {
+ Vector3 position = orbital.transform.position;
+ Vector3 ownerPos = owner.transform.position;
+ orbital.transform.LookAt(2 * position - new Vector3(ownerPos.x, position.y, ownerPos.z));
+ }
+
+ private void GetInput(GameObject orbital, Vector2 inputDir)
+ {
+ 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;
+ }
+ }
+}
diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset
@@ -0,0 +1,20 @@
+%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: 5d7968acda84baa4fa1a7008b6f01265, type: 3}
+ m_Name: InputOrbitalLogic
+ m_EditorClassIdentifier:
+ rotSpeed: 60
+ yOffset: 1
+ xAxis: 2.2
+ zAxis: 2.2
+ orbitalInputTrigger: {fileID: 11400000, guid: 4c7d44de3d4eecc438c60d97a9a2874b,
+ type: 2}
diff --git a/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset.meta b/Assets/Scripts/Slimecing/Swords/Orbitals/SOOrbitalLogic/InputOrbitalLogic.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e77fb33472e993c4fbd1004f42fc4ed2
+NativeFormatImporter:
+ externalObjects: {}
+ mainObjectFileID: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset b/Assets/Scripts/Slimecing/Triggers/SOTrigger/AxisInputTrigger.asset
@@ -0,0 +1,16 @@
+%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
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 4c7d44de3d4eecc438c60d97a9a2874b
+NativeFormatImporter:
+ externalObjects: {}
+ mainObjectFileID: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs
@@ -3,8 +3,8 @@ using UnityEngine.InputSystem;
namespace Slimecing.Triggers.TriggerLogic
{
- [CreateAssetMenu(fileName = "TwoDimensionalAxisInputTrigger ", menuName = "Triggers/InputTriggers/TwoDimensionalAxisInputTrigger ")]
- public class TwoDimensionalAxisInputTrigger : TriggerInput
+ [CreateAssetMenu(fileName = "AxisInputTrigger ", menuName = "Triggers/InputTriggers/AxisInputTrigger ")]
+ public class AxisInputTrigger : TriggerInput
{
protected override void TriggerStarted(GameObject player, InputAction.CallbackContext ctx)
{
diff --git a/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs.meta b/Assets/Scripts/Slimecing/Triggers/TriggerLogic/AxisInputTrigger.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b724fbf88219cb4459211c90795c6464
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: