Syntriax b6dbfea477 | ||
---|---|---|
Bases | ||
Config | ||
Editor | ||
Implementations | ||
ToggleState@6afed7407d | ||
Trigger@dabe16b529 | ||
.gitignore | ||
.gitmodules | ||
Bases.meta | ||
Config.meta | ||
Editor.meta | ||
IMovement.cs | ||
IMovement.cs.meta | ||
IMovementController.cs | ||
IMovementController.cs.meta | ||
IMovementControllerExtensions.cs | ||
IMovementControllerExtensions.cs.meta | ||
IMovementExtensions.cs | ||
IMovementExtensions.cs.meta | ||
Implementations.meta | ||
MovementController.cs | ||
MovementController.cs.meta | ||
README.md | ||
README.md.meta | ||
Syntriax.Modules.Movement.asmdef | ||
Syntriax.Modules.Movement.asmdef.meta | ||
ToggleState.meta | ||
Trigger.meta |
README.md
Movement (Work In Progress)
Getting Started 2D (Quick)
- Clone the module to a folder in your Assets folder
- Add
MovementController
component to your PlayerGameObject
- Add
GroundMovement1D
component 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
ToggleStateMonoBehaviour
component to your PlayerGameObject
- Add
MovementController
component to your PlayerGameObject
- Add
AirMovement1D
component to your PlayerGameObject
- Add
GroundMovement1D
component to your PlayerGameObject
(make sure it's bellowAirMovement1D
) - Add a new empty child
GameObject
and addBox2DColliderTrigger
component to it and place and resize it under the player for ground detection, optionally you can set theCollisionMask
field 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();
}
}