6e52abee2a042f99e0b0125945ea938ae5331d7c
Movement
Getting Started 2D (Quick)
- Clone the module to a folder in your Assets folder
- Add
MovementControllercomponent to your PlayerGameObject - Add
GroundMovement1Dcomponent to your PlayerGameObject - Connect your inputs to the
MovementController(Example with Input System)
Getting Started 2D (Longer)
- Clone the module to a folder in your Assets folder
- Add
ToggleStateMonoBehaviourcomponent to your PlayerGameObject - Add
MovementControllercomponent to your PlayerGameObject - Add
AirMovement1Dcomponent to your PlayerGameObject - Add
GroundMovement1Dcomponent to your PlayerGameObject(make sure it's bellowAirMovement1D) - Add a new empty child
GameObjectand addBox2DColliderTriggercomponent to it and place and resize it under the player for ground detection, optionally you can set theCollisionMaskfield on it to make sure it only detects specific layers - Connect your inputs to the
MovementController(Example with Input System) - (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();
}
}
Description
Languages
C#
100%