Movement module for Unity
Go to file
Syntriax 28ad0be11b 0.2.1 2023-03-21 16:31:48 +03:00
Editor BREAKING CHANGE: Toggle 0.2.0 2023-03-20 22:39:21 +03:00
Runtime refactor: Added Backing Fields to BaseSpeed & MovementMultiplier to Expose to Editor 2023-03-21 16:05:55 +03:00
Samples feat: Sample Air Movement Updated 2023-03-21 16:31:01 +03:00
.gitignore Initial commit 2021-12-06 11:33:22 +03:00
.gitmodules Removed Submodules 2022-11-21 21:02:23 +03:00
Editor.meta Editor First Commit 2022-11-16 15:53:06 +03:00
README.md docs: Updated README.md 2023-03-21 16:31:00 +03:00
README.md.meta First Readme 2022-11-15 17:46:07 +03:00
Runtime.meta Unity Package Structure 2022-12-15 19:24:01 +03:00
Samples.meta Moved few Implemantations to Samples Folder 2022-12-17 12:04:14 +03:00
package.json 0.2.1 2023-03-21 16:31:48 +03:00
package.json.meta Meta Files and Fix 2022-12-13 14:06:01 +03:00

README.md

Movement (Work In Progress)

Installation

UPM

  1. Add the UPM registry. Click on the Edit menu, then select Project settings..., select Package Manager, and add a scoped registry:
    • Name: Syntriax
    • Url: https://upm.syntriax.com
    • Scopes:
      • com.syntriax

The UPM registry also has proxies to OpenUPM, so you can add scopes from there too.

Manual

  1. Navigate into Package Manager and press on the + button, choose Add package from git URL... and add:
    • https://git.syntriax.com/Syntriax/State
    • https://git.syntriax.com/Syntriax/Trigger
    • https://git.syntriax.com/Syntriax/Factory
    • https://git.syntriax.com/Syntriax/Movement

Dependencies

  1. State Module (https://git.syntriax.com/Syntriax/State)
  2. Trigger Module (https://git.syntriax.com/Syntriax/Trigger)
  3. Factory Module (https://git.syntriax.com/Syntriax/Factory)

Getting Started 2D

Automaticaly

Custom The Editor

  1. Find the button on the Unity Editor's top panel named Syntriax, Under Modules/Movement open the window Definition Creator
  2. You can find two buttons for both Quick and Longer presets, or you can define your own, then press Create button
  3. Add MovementDefinitionApplier component to your Player GameObject
  4. Put the name of the definition you created in the first step to Startup Definition Name field
    • You can also call MovementDefinitionApplier.LoadDefinition method manually to load them via anoher script.
  5. Connect your inputs to the MovementController (Example with Input System)

Manually

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)

Longer

  1. Clone the module to a folder in your Assets folder
  2. Add StateEnableMonoBehaviour 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 Box2DGroundTrigger & GroundTrigger 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 IStateEnable, 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<IMovementController>();

    inputs.Enable();
  }

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