diff --git a/Implementations.meta b/Implementations.meta new file mode 100644 index 0000000..c14cbc9 --- /dev/null +++ b/Implementations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 15528ebd51d27d54398c55826710f23e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Implementations/AirMovement1D.cs b/Implementations/AirMovement1D.cs new file mode 100644 index 0000000..0f4e35e --- /dev/null +++ b/Implementations/AirMovement1D.cs @@ -0,0 +1,44 @@ +using Syntriax.Modules.Trigger; +using UnityEngine; + +namespace Syntriax.Modules.Movement.Implementations +{ + [RequireComponent(typeof(Rigidbody2D))] + public class AirMovement1D : MovementBase1D + { + protected override float moveValue { get; set; } = 0f; + protected IGroundTrigger groundTrigger = null; + protected Rigidbody2D rigid = null; + + protected override void Start() + { + base.Start(); + + rigid = GetComponent(); + groundTrigger = GetComponentInChildren(); + groundTrigger.OnTriggered += OnGroundTrigger; + } + + private void OnGroundTrigger(bool isGrounded) + => CanTakeOver = !isGrounded; + + public override void ApplyMovement() + { + Vector2 velocity = rigid.velocity; + velocity.x += moveValue * Time.fixedDeltaTime; + + if (moveValue != 0f) + { + if (Mathf.Abs(velocity.x) > Mathf.Abs(moveValue)) + velocity.x = moveValue; + else if (Mathf.Abs(velocity.x - moveValue) > Mathf.Abs(moveValue)) + velocity.x += moveValue * Time.fixedDeltaTime; + } + + rigid.velocity = velocity; + } + + protected override void OnDeactivated() { } + protected override void OnActivated() { } + } +} diff --git a/Implementations/AirMovement1D.cs.meta b/Implementations/AirMovement1D.cs.meta new file mode 100644 index 0000000..06cb391 --- /dev/null +++ b/Implementations/AirMovement1D.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 69ca5998eb951b64499b111100275018 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Implementations/GroundMovement1D.cs b/Implementations/GroundMovement1D.cs new file mode 100644 index 0000000..e9a1f39 --- /dev/null +++ b/Implementations/GroundMovement1D.cs @@ -0,0 +1,35 @@ +using Syntriax.Modules.Trigger; +using UnityEngine; + +namespace Syntriax.Modules.Movement.Implementations +{ + [RequireComponent(typeof(Rigidbody2D))] + public class GroundMovement1D : MovementBase1D + { + protected override float moveValue { get; set; } = 0f; + protected IGroundTrigger groundTrigger = null; + protected Rigidbody2D rigid = null; + + protected override void Start() + { + base.Start(); + + rigid = GetComponent(); + groundTrigger = GetComponentInChildren(); + groundTrigger.OnTriggered += OnGroundTrigger; + } + + private void OnGroundTrigger(bool isGrounded) + => CanTakeOver = isGrounded; + + public override void ApplyMovement() + { + Vector2 velocity = rigid.velocity; + velocity.x = moveValue; + rigid.velocity = velocity; + } + + protected override void OnDeactivated() { } + protected override void OnActivated() { } + } +} diff --git a/Implementations/GroundMovement1D.cs.meta b/Implementations/GroundMovement1D.cs.meta new file mode 100644 index 0000000..3a76211 --- /dev/null +++ b/Implementations/GroundMovement1D.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 10b59caf08f3e2d4b94eb72b7885346d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: