From e7dc0c7580523d8f3f273b187d2872fd0bb07403 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Tue, 15 Nov 2022 17:46:07 +0300 Subject: [PATCH] First Readme --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md.meta | 7 +++++ 2 files changed, 77 insertions(+) create mode 100644 README.md create mode 100644 README.md.meta diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b50a29 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# Movement + +--- + +## Getting Started 2D (Quick) + +1. Clone the module to a folder in your Assets folder +2. Add `MovementController` component to your Player `GameObject` +3. Add `GroundMovement1D` component to your Player `GameObject` +4. Connect your inputs to the `MovementController` ([Example with Input System](#input-system-example)) + +--- + +## Getting Started 2D (Longer) + +1. Clone the module to a folder in your Assets folder +2. Add `ToggleStateMonoBehaviour` component to your Player `GameObject` +3. Add `MovementController` component to your Player `GameObject` +4. Add `AirMovement1D` component to your Player `GameObject` +5. Add `GroundMovement1D` component to your Player `GameObject` (make sure it's bellow `AirMovement1D`) +6. Add a new empty child `GameObject` and add `Box2DColliderTrigger` component to it and place and resize it under the player for ground detection, optionally you can set the `CollisionMask` field on it to make sure it only detects specific layers +7. Connect your inputs to the `MovementController` ([Example with Input System](#input-system-example)) +8. (Optional) Add a jumping script to see the effects better + +--- + +This should give you a movement where you can disable the controller through the `IToggleState`, and you should be able to see a the movement changes when the character is not touching the ground. + +You can add your own movement implementations with bases under the `Bases` folder, or straight up from the `IMovement` interface. + +Or if you want you can write your own `MovementController` with using the `IMovementController` interface, too, but it should be enough for most cases. + +--- + +### Input System Example + +```cs +using Syntriax.Modules.Movement; +using UnityEngine; +using UnityEngine.InputSystem; + +public class MovementInputs : MonoBehaviour, Inputs.IMovementActions +{ + private Inputs inputs = null; + + private IMovementController movementController = null; + + public void OnMovement(InputAction.CallbackContext context) => + movementController.Move(context.ReadValue()); + + private void OnEnable() + { + if (inputs == null) + { + inputs = new Inputs(); + inputs.Movement.SetCallbacks(this); + } + + movementController = + movementController ?? FindObjectOfType(); + + inputs.Enable(); + } + + private void OnDisable() + { + inputs.Disable(); + } +} +``` diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..086e038 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f76e696e0c24ddc438f11868f8c9b855 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: