Movement module for Unity
Go to file
Syntriax e7dc0c7580 First Readme 2022-11-15 17:46:07 +03:00
Bases Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
Config Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
Implementations Default Movement Added 2022-11-15 16:26:26 +03:00
ToggleState@463182ab43 Added Error Reporting & Updated The Submodules & Bug Fixes 2022-11-14 14:22:18 +03:00
Trigger@b7fafaa09f Trigger Submodule Updated 2022-11-14 14:28:18 +03:00
.gitignore Initial commit 2021-12-06 11:33:22 +03:00
.gitmodules Trigger Submodule Added (Previously named ColliderCheck) 2022-11-14 13:12:39 +03:00
Bases.meta Added New Bases and removed Air and Ground Movement Implementations Temporarily 2022-11-14 12:41:11 +03:00
Config.meta Configs and Factories added 2022-03-17 22:43:47 +03:00
IMovement.cs Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
IMovement.cs.meta First Commit 2021-12-23 12:41:01 +03:00
IMovementController.cs Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
IMovementController.cs.meta IMovementController Added 2022-03-07 11:22:29 +03:00
IMovementControllerExtensions.cs Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
IMovementControllerExtensions.cs.meta Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
IMovementExtensions.cs Added IMovementController.Move method & Added Some Documentation 2022-11-15 13:08:37 +03:00
IMovementExtensions.cs.meta First Commit 2021-12-23 12:41:01 +03:00
Implementations.meta Air & Ground Movement Implementations Added Back 2022-11-14 13:21:35 +03:00
MovementController.cs Default Movement Added 2022-11-15 16:26:26 +03:00
MovementController.cs.meta Added OnMovement Activated&Deactivated to the IMovementController 2022-03-13 20:59:45 +03:00
README.md First Readme 2022-11-15 17:46:07 +03:00
README.md.meta First Readme 2022-11-15 17:46:07 +03:00
Syntriax.Modules.Movement.asmdef Converted Toggle State to a Submodule 2022-11-14 13:04:09 +03:00
Syntriax.Modules.Movement.asmdef.meta Added Reset()s and Initialize()s made public in Factories + Fix & Upgrades 2022-03-19 14:02:13 +03:00
ToggleState.meta Converted Toggle State to a Submodule 2022-11-14 13:04:09 +03:00
Trigger.meta Trigger Submodule Added (Previously named ColliderCheck) 2022-11-14 13:12:39 +03:00

README.md

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)

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)
  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

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<Vector2>());

  private void OnEnable()
  {
    if (inputs == null)
    {
      inputs = new Inputs();
      inputs.Movement.SetCallbacks(this);
    }

    movementController =
      movementController ?? FindObjectOfType<MovementController>();

    inputs.Enable();
  }

  private void OnDisable()
  {
    inputs.Disable();
  }
}