Movement/README.md

90 lines
3.4 KiB
Markdown
Raw Normal View History

2022-11-15 18:41:37 +03:00
# Movement (Work In Progress)
2022-11-15 17:46:07 +03:00
2022-11-16 21:50:54 +03:00
## Dependencies
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
2. [Trigger Module](https://git.syntriax.com/Syntriax/Trigger)
Make sure to clone these modules along with this one.
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 `Movement` module)
---
## Getting Started 2D
2022-11-18 12:18:35 +03:00
### 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`
2022-11-18 14:25:40 +03:00
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
2022-11-18 12:18:35 +03:00
- You can also call `MovementDefinitionApplier.LoadDefinition` method manually to load them via anoher script.
2022-11-18 14:25:40 +03:00
5. Connect your inputs to the `MovementController` ([Example with Input System](#input-system-example))
2022-11-18 12:18:35 +03:00
### Manually
#### Quick
2022-11-15 17:46:07 +03:00
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](#input-system-example))
2022-11-18 12:18:35 +03:00
#### Longer
2022-11-15 17:46:07 +03:00
1. Clone the module to a folder in your Assets folder
2. Add `ToggleStateMonoBehaviour` 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 `Box2DColliderTrigger` 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](#input-system-example))
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 `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
```cs
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();
}
}
```