Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

In order to add a new mechanic (something that needs a new input other than the existing ones) you have a few steps to do:

  1. Edit the Unity's Input asset (located in Sample/Input/Top Down Controller 2D in the example) to add a new input to read
  2. Create a new event for this input in the TopDownCharacter2D.Controllers.ControllerEvent class by following the existing examples (for a dodge mechanic I think you want your event to extend the UnityEvent<Vector2> 'class' since you want to dodge in a specific direction I would imagine)
  3. Add your new event to the TopDownCharacterController class (simply add a private readonly field and a public getter like the other events)
  4. Now if you want the player to be able to use your new mechanic you need to update your player controller (your class extending the TopDownCharacterController class / the TopDownInputController class in the example). 
  5. In this class you will need to create a method to receive the input from the input system (like the OnMove and OnLook methods of this class) for a dodge mechanic i think you will need to keep a direction in memory and when you press the button you create a OnDodgeEvent with the direction stored (using the look direction should work quite well)
  6. Now you only need to create a new component to handle this specific event. In order to write this component you can look at the TopDownMovement, TopDownAimRotation, TopDownShooting... classes which basically work the same way. 
    1. You need to store your controller using "GetComponent<TopDownCharacterController>" in the Awake method
    2. Add a listener to the event you want to handle (OnDodgeEvent in this example)
    3. And finally, actually perform the logic of the mechanic in the method

Now as for the dodge mechanic in itself i think you should use a Coroutine (https://docs.unity3d.com/Manual/Coroutines.html) which will simply disable collision between the player and enemies / bullets and some components like TopDownMovement and HealthSystem for a given time. I think this page can be a good start https://docs.unity3d.com/ScriptReference/Physics.IgnoreLayerCollision.html

If you want a specific animation for the dodge you can look into the TopDownAnimation class and add a listener on the OnDodgeEvent.

These steps should help you to add a new mechanic to the controller, but if you encounter any problem or don't understand a step don't hesitate to ask me in the future i plan on writing a small documentation properly to answer those kind of questions.

wow, amazing response, very detailed, and very quick, i'll be sure to give it a go today or tomorrow at some point, and i'll keep you posted! Thanks!