Syntriax e2c1f186af | ||
---|---|---|
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 | ||
MovementDefinitionApplier.cs | ||
MovementDefinitionApplier.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)
Dependencies
Make sure to separately clone these modules along with this one too.
Or you can call git submodule init
to get them automatically added (note that this method may cause conflicts if another module also imports one of these submodules too, only use if you are only using the Movement
module)
Getting Started 2D
Automaticaly
Custom The Editor
- Find the button on the Unity Editor's top panel named
Syntriax
, UnderModules/Movement
open the windowDefinition Creator
- You can find two buttons for both
Quick
andLonger
presets, or you can define your own, then pressCreate
button - Add
MovementDefinitionApplier
component to your PlayerGameObject
- 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.
- You can also call
- Connect your inputs to the
MovementController
(Example with Input System)
Manually
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)
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<IMovementController>();
inputs.Enable();
}
private void OnDisable()
{
inputs.Disable();
}
}