A downloadable asset pack

Download NowName your own price

Description

This project is a Unity package containing scripts as well as example assets/scene. The example scene uses Unity's new input system by default as well as cinemachine for the follow camera, you will need to install them via Unity's package manager in order for the example to work properly.

This package is compatible with Unity 2019.3 or newer versions.

This project contains a lot of scripts to allow the user to easily customize the behaviors attached to an entity. 

The full version include a documentation explaining how to use the package and also how to modify the existing code if needed. It also contains newer revisions of some parts of the code.  

Features

  • Top down movement with 2D sprites
  • Top down shooting mechanic
  • Top down melee attack mechanic
  • Health and damage system
  • Reusable scripts between player and enemies
  • Sound and visual effects system
  • Highly customizable stats and power-ups
  • Playable with mouse/keyboard or with a controller
  • Easy to implements enemy AIs

How it works

In order to use this package you should check the example scene located at Sample/Scenes/TopDownExampleScene. This scene and its content should give you a rough idea of how this system works.

This packages uses dynamic rigidbodies for the physics and movements and by playing with its values as well as the speed of the character you can achieve different style of movement.

This packages also uses Unity's tags and layers systems so be careful to properly set those in order for the enemies to behave properly and the bullets to actually hit the right type of entities.

For an entity to be valid it needs at least a script extending from TopDownCharacterController this script will be in charge of creating the events (such as OnMove, OnAttack...) and transmit them to the other components of the system. In case you want an entity to have an AI you can take a look at some other example controllers (Scripts/Controllers/TopDownRangeEnemyControler for example) to see how to write your own implementation.

An entity will also need a CharacterStatHandler component to work since it contains some important values such as the speed and max health of the entity, as well as its attack properties (At the moment the an attack can be both ranged with a gun or melee, and a configuration for those attacks can be created by right clicking in the project hierarchy and selecting Create -> TopDownController -> Attacks -> Shoot / CloseCombat)

Feel free to ask questions in the comments if you need help with something.

Download

Download NowName your own price

Click download now to get access to the following files:

Top Down Controller 2D v1.0 559 kB

Development log

Comments

Log in with itch.io to leave a comment.

hello sir, i am very interested. It's just what I need, but my project is designed for mobile(android), is there any way to include touch controls?

You could theoretically just edit the InputAction file of your Player to add ways to triggers the Move, Look and Fire events with touch controls. However i don't think just doing this would work very well so you might need some kind of virtual joystick and buttons or at least a custom version of my "TopDownInputController" script. I might try to implement touch controls later but not in the near future.

hey i purchased this asset the other day and was curious as to how i would go about adding a player dodge/dash mechanic? and what i would have to disable to go about doing that.

(+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!

Nice, I was looking for something like this for months, good controller.

but it gives me 4 errors when I import it

first error:  Assets\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(2,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

second error:  Assets\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(24,28): error CS0246: The type or namespace name 'InputValue' could not be found (are you missing a using directive or an assembly reference?)

third error: Assets\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(34,28): error CS0246: The type or namespace name 'InputValue' could not be found (are you missing a using directive or an assembly reference?)

and forth error:

Assets\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(53,28): error CS0246: The type or namespace name 'InputValue' could not be found (are you missing a using directive or an assembly reference?)

Dont worry, I fixed it, it was because I didnt had the input system package.

Assets\Scripts\TopDownCharacter2D\Controllers\TopDownCharacterController.cs(21,51): error CS0144: Cannot create an instance of the abstract class or interface 'UnityEvent<Vector2>'

help plz

Which Unity version are you using ?

2019.4.28f1

(+1)

I'm working on porting it to Unity 2019, however if that's not a problem for you you can try to use Unity 2020 and it should work properly.

well i like to use 2019 verson so hope you fix the problem thankyou

(+1)

I uploaded a new version compatible with Unity 2019

it seems that this project is built on the new Input System, maybe should stress this in the description?

It was only mentioned in the installation instructions but its easy to miss so I added it in the description now. However if it's a problem for you, porting it to the old input system should be really easy since only the controller would need to be reworked (I might add an example with the old input system later)

No I'm ok with that, I just feel like it's better to mention in the description in case someone miss that. Btw it's a really good asset:)

I will study this for my next project, thanks