Syntriax a4bb04860c | ||
---|---|---|
Editor | ||
Runtime | ||
Samples | ||
.gitignore | ||
.gitmodules | ||
Editor.meta | ||
README.md | ||
README.md.meta | ||
Runtime.meta | ||
Samples.meta | ||
package.json | ||
package.json.meta |
README.md
Movement (Work In Progress)
Dependencies
Make sure to separately clone these modules along with this one too.
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
StateEnableMonoBehaviour
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 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();
}
}