From 775e8b93ef645a77d5cdb25968c9a6d3cf4b06b4 Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Thu, 19 Sep 2019 15:32:34 +1000 Subject: [PATCH] Fixed Diagonal + added Wait --- Assets/Data/Inventory/BaseInventory.asset | 4 +- Assets/Data/Logic Blocks/Diagonal L.asset | 2 +- Assets/Data/Logic Blocks/Rotate Half L.asset | 3 ++ .../Logic Blocks/Rotate Half L.asset.meta | 8 ++++ Assets/Data/Logic Blocks/Rotate Half R.asset | 3 ++ .../Logic Blocks/Rotate Half R.asset.meta | 8 ++++ Assets/Data/Logic Blocks/Wait.asset | 3 ++ Assets/Data/Logic Blocks/Wait.asset.meta | 8 ++++ .../{Scripts/Components.meta => Models.meta} | 2 +- Assets/Plugins.meta | 8 ++++ Assets/Plugins/IngameDebugConsole.meta | 8 ++++ .../Plugins/IngameDebugConsole/Android.meta | 8 ++++ .../Plugins/IngameDebugConsole/Prefabs.meta | 8 ++++ .../Plugins/IngameDebugConsole/Scripts.meta | 8 ++++ .../Plugins/IngameDebugConsole/Sprites.meta | 8 ++++ .../IngameDebugConsole/Sprites/Unused.meta | 8 ++++ Assets/Scripts/Character.cs | 48 +++++++++++++------ Assets/Scripts/KeyboardInput.cs | 4 +- Assets/Scripts/Logic/Blocks/Rotate.cs | 25 ++++++++-- Assets/Scripts/LogicBlocks.meta | 8 ++++ 20 files changed, 157 insertions(+), 25 deletions(-) create mode 100644 Assets/Data/Logic Blocks/Rotate Half L.asset create mode 100644 Assets/Data/Logic Blocks/Rotate Half L.asset.meta create mode 100644 Assets/Data/Logic Blocks/Rotate Half R.asset create mode 100644 Assets/Data/Logic Blocks/Rotate Half R.asset.meta create mode 100644 Assets/Data/Logic Blocks/Wait.asset create mode 100644 Assets/Data/Logic Blocks/Wait.asset.meta rename Assets/{Scripts/Components.meta => Models.meta} (77%) create mode 100644 Assets/Plugins.meta create mode 100644 Assets/Plugins/IngameDebugConsole.meta create mode 100644 Assets/Plugins/IngameDebugConsole/Android.meta create mode 100644 Assets/Plugins/IngameDebugConsole/Prefabs.meta create mode 100644 Assets/Plugins/IngameDebugConsole/Scripts.meta create mode 100644 Assets/Plugins/IngameDebugConsole/Sprites.meta create mode 100644 Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta create mode 100644 Assets/Scripts/LogicBlocks.meta diff --git a/Assets/Data/Inventory/BaseInventory.asset b/Assets/Data/Inventory/BaseInventory.asset index ff3f79a..f1655d2 100644 --- a/Assets/Data/Inventory/BaseInventory.asset +++ b/Assets/Data/Inventory/BaseInventory.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ffe4ea933ab9da92364324d81c2749faee272a1748758219ee2fa21b503e5044 -size 1059 +oid sha256:07fcd4acc0a169da62bb9e580f52c4c1002bb75840e34c8f645646d3101be1c7 +size 1186 diff --git a/Assets/Data/Logic Blocks/Diagonal L.asset b/Assets/Data/Logic Blocks/Diagonal L.asset index 50d7cf6..4eee4b5 100644 --- a/Assets/Data/Logic Blocks/Diagonal L.asset +++ b/Assets/Data/Logic Blocks/Diagonal L.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8ab0be1c04b5733f302cf6294b114f646c748d72a57b95620f0e4476e557d576 +oid sha256:35b10cb1265be2f97a08ddbe4c1142651c6b98a2fcfe480b9ca91a5593a550bc size 871 diff --git a/Assets/Data/Logic Blocks/Rotate Half L.asset b/Assets/Data/Logic Blocks/Rotate Half L.asset new file mode 100644 index 0000000..2450648 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Half L.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef1cf0fb60605b274187de1b9550192ca070e6dfce03cafaec0ad84292a0bebf +size 583 diff --git a/Assets/Data/Logic Blocks/Rotate Half L.asset.meta b/Assets/Data/Logic Blocks/Rotate Half L.asset.meta new file mode 100644 index 0000000..3572963 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Half L.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 087b44b5a4243a04ca6cc76601a56c93 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Logic Blocks/Rotate Half R.asset b/Assets/Data/Logic Blocks/Rotate Half R.asset new file mode 100644 index 0000000..91b726f --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Half R.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb3ab44d98fbeb03c9b7e1d11c86619f2db347f2831c0014ebd5c048bc3f55b9 +size 583 diff --git a/Assets/Data/Logic Blocks/Rotate Half R.asset.meta b/Assets/Data/Logic Blocks/Rotate Half R.asset.meta new file mode 100644 index 0000000..3735aa3 --- /dev/null +++ b/Assets/Data/Logic Blocks/Rotate Half R.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 73853329caa830f4ca424d96ce58d589 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Logic Blocks/Wait.asset b/Assets/Data/Logic Blocks/Wait.asset new file mode 100644 index 0000000..6bd6514 --- /dev/null +++ b/Assets/Data/Logic Blocks/Wait.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6475a06eeda44fd342624dfe1b8a353fcbb2e3fe56665c4747e00928f3d2f670 +size 574 diff --git a/Assets/Data/Logic Blocks/Wait.asset.meta b/Assets/Data/Logic Blocks/Wait.asset.meta new file mode 100644 index 0000000..e8a258e --- /dev/null +++ b/Assets/Data/Logic Blocks/Wait.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7efcab7b8763f334ebf47148baaf4f0c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Components.meta b/Assets/Models.meta similarity index 77% rename from Assets/Scripts/Components.meta rename to Assets/Models.meta index 5a95b09..5346456 100644 --- a/Assets/Scripts/Components.meta +++ b/Assets/Models.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8d7394d70ec233849a60a26da5f23b75 +guid: 296bd90e667df1f4697823a0aa45acf0 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Plugins.meta b/Assets/Plugins.meta new file mode 100644 index 0000000..aa3b71c --- /dev/null +++ b/Assets/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eb6762a6d45772b43a77849ba46f89db +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole.meta b/Assets/Plugins/IngameDebugConsole.meta new file mode 100644 index 0000000..36375af --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5f8eae876be4b03438375a82d2c69b4d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole/Android.meta b/Assets/Plugins/IngameDebugConsole/Android.meta new file mode 100644 index 0000000..12049b6 --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Android.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3d7d7a61a5341904eb3c65af025b1d86 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole/Prefabs.meta b/Assets/Plugins/IngameDebugConsole/Prefabs.meta new file mode 100644 index 0000000..6aa8bf2 --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7dbc36665bc0d684db9a4447e27a7a4b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole/Scripts.meta b/Assets/Plugins/IngameDebugConsole/Scripts.meta new file mode 100644 index 0000000..72dcaac --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 860c08388401a6d4e858fe4910ea9337 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole/Sprites.meta b/Assets/Plugins/IngameDebugConsole/Sprites.meta new file mode 100644 index 0000000..504a23d --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Sprites.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb5d7b23a9e684a41a6a5d4f300eb1e6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta b/Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta new file mode 100644 index 0000000..f3769b1 --- /dev/null +++ b/Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6caae32d463529478f2186f47c2e3fe +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 6b1bfea..68d5b9d 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -134,17 +134,16 @@ public class Character : MonoBehaviour - public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true) + public IEnumerator RotateInDirection(Direction direction,float angles, Animation animation, float time) { System.Func yFunction = null; if (animation == Animation.Jump) yFunction = (t) => Mathf.Sin((Mathf.PI * t)); - Vector3 _endDir = isLocal ? direction.ToVector(transform) : direction.ToVector(); - StartAnimation(animation, time); - yield return StartCoroutine(LerpToRotation(_endDir, time * 0.8f, yFunction)); + Debug.Log("Rotating by: " + angles); + yield return StartCoroutine(Rotate(direction,angles, time * 0.8f, yFunction)); StopAnimation(animation); } @@ -158,6 +157,9 @@ public class Character : MonoBehaviour Vector3 _newPos; float elapsedTime = 0; + + + while (elapsedTime / time < 1) { @@ -180,34 +182,50 @@ public class Character : MonoBehaviour transform.position = _newPos; } - private IEnumerator LerpToRotation(Vector3 target, float time, System.Func heightOffset = null) + private IEnumerator Rotate(Direction direction, float angles, float time, System.Func heightOffset = null) { - Vector3 _startDir = transform.forward; - Vector3 _endDir = target; + int RotationDir = 0; + switch (direction) + { + case Direction.Forward: + RotationDir = 0; + break; + case Direction.Left: + RotationDir = -1; + break; + case Direction.Right: + RotationDir = 1; + break; + case Direction.Back: + RotationDir = 2; + break; + } + - Vector3 _startPos = transform.position; float elapsedTime = 0; - while (elapsedTime / time < 1) - { + float anglePerSecond = (angles * RotationDir) / time; + Vector3 _startPos = transform.position; + Vector3 startDirection = transform.forward; - transform.forward = Vector3.Slerp(_startDir, _endDir, (elapsedTime / time)); + while (elapsedTime < time) + { + transform.Rotate(Vector3.up, anglePerSecond * Time.deltaTime); if (heightOffset != null) - transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); + transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); yield return new WaitForEndOfFrame(); - elapsedTime += Time.deltaTime; } - transform.forward = target; - + transform.forward = Quaternion.AngleAxis(angles * RotationDir, Vector3.up) * startDirection; if (heightOffset != null) transform.position = _startPos + Vector3.up * heightOffset(1); } + public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time) { System.Func yFunction = null; diff --git a/Assets/Scripts/KeyboardInput.cs b/Assets/Scripts/KeyboardInput.cs index 0d12796..3e64e89 100644 --- a/Assets/Scripts/KeyboardInput.cs +++ b/Assets/Scripts/KeyboardInput.cs @@ -25,11 +25,11 @@ public class KeyboardInput : MonoBehaviour if (Input.GetKeyDown(KeyCode.LeftArrow)) { - StartCoroutine(character.RotateToDirection(Direction.Left, Character.Animation.Jump, characterSpeed, true)); + StartCoroutine(character.RotateInDirection(Direction.Left,90, Character.Animation.Jump, characterSpeed)); } if (Input.GetKeyDown(KeyCode.RightArrow)) { - StartCoroutine(character.RotateToDirection(Direction.Right, Character.Animation.Jump, characterSpeed, true)); + StartCoroutine(character.RotateInDirection(Direction.Right, 90, Character.Animation.Jump, characterSpeed)); } if (Input.GetKeyDown(KeyCode.UpArrow)) { diff --git a/Assets/Scripts/Logic/Blocks/Rotate.cs b/Assets/Scripts/Logic/Blocks/Rotate.cs index e195418..52b2541 100644 --- a/Assets/Scripts/Logic/Blocks/Rotate.cs +++ b/Assets/Scripts/Logic/Blocks/Rotate.cs @@ -14,6 +14,10 @@ public class Rotate : LogicBlock [Header("Rotate Settings")] [Tooltip("Direction to rotate in")] protected Direction direction; + + [SerializeField] + [Tooltip("Angle in Degrees")] + protected int Angle = 90; #endregion Inspector Fields @@ -27,7 +31,8 @@ public class Rotate : LogicBlock { //player.Rotate(direction, animationTime); - yield return player.StartCoroutine(player.RotateToDirection(direction, Character.Animation.Jump, animationTime, true)); + Debug.Log("Rotating by: " + Angle); + yield return player.StartCoroutine(player.RotateInDirection(direction,Angle, Character.Animation.Jump, animationTime)); } /// @@ -45,19 +50,31 @@ public class Rotate : LogicBlock public override void CopyToken(BlockToken token) { base.CopyToken(token); - direction = ((DirectionToken)token).direction; + direction = ((RotateToken)token).direction; + Angle = ((RotateToken)token).angle; } public override BlockToken ToToken(BlockToken token = null) { if (token == null) - token = new DirectionToken(this); + token = new RotateToken(this); - DirectionToken retVal = (DirectionToken)base.ToToken(token); + RotateToken retVal = (RotateToken)base.ToToken(token); retVal.direction = direction; + retVal.angle = Angle; + return retVal; } #endregion Class Functions } + +[System.Serializable] +public class RotateToken : BlockToken +{ + public Direction direction; + public int angle; + + public RotateToken(LogicBlock block) : base(block) { } +} diff --git a/Assets/Scripts/LogicBlocks.meta b/Assets/Scripts/LogicBlocks.meta new file mode 100644 index 0000000..98af9d1 --- /dev/null +++ b/Assets/Scripts/LogicBlocks.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8936b441d7647f74884c94f97bfb8931 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: