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.

Installation

This plugin is compatible with Unity 2019 or older, before importing the plugin in your project, make sure that your:

  • Install the Input System and Cinemachine package (To install a package from Unity go to Window -> Package Manager -> Search for the name of the package and install the plugin (if you can't find it in the results make sure that you set the list of packages to display the content of Unity registry at the top left of the window))
  • Make sure your project uses the new Input System package (Edit -> Project Settings -> Player -> Other Settings -> Active Input handling -> Input System Package (new)

After that if your have any issue try to re-import the plugin and restart the editor, if the issue persist please feel free to leave a comment with the error you're facine and the Unity version you are using.

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.

StatusReleased
CategoryAssets
Rating
Rated 4.9 out of 5 stars
(7 total ratings)
AuthorNyanYann
Made withUnity
Tags2D, Controller, Singleplayer, Project template, Top-Down, Top down shooter, Unity
Code licenseMIT License
Average sessionAbout a half-hour
InputsKeyboard, Mouse, Xbox controller, Gamepad (any)

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.

(+1)

thnks i managed to make a pretty solid base for the game i am making, so right now i can play with the graphics

Note, to anyone using this, if you're using this and try to playtest in the editor, you cannot move, you can only do it in the Player and not in the Editor. I think this may have something to do with the Input Manager being used.

(3 edits)

New to unity, downloaded on 2022.3.4f1 with 2 errors

Assets\TopDownController2D\Scripts\TopDownCharacter2D\UI\EntityHealthGaugeUpdater.cs(4,19): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

Assets\TopDownController2D\Scripts\TopDownCharacter2D\UI\EntityHealthGaugeUpdater.cs(13,34): error CS0246: The type or namespace name 'Slider' could not be found (are you missing a using directive or an assembly reference?)

How to fix? And yes, Cinemachine and Input System are installed

Edit: Seems that UnityEngine.UI (Line 4) isn't a proper namespace type and removing it seems to fix it. And "Slider" (Line 13)... isn't a real thing? Did you mean SliderEditor?

UnityEngine.UI is indeed a valid Unity namespace https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.html and it's a built-in package in Unity, Maybe you have it disabled in the package manager? (Window->Package Manager ->Select Package: Built-in -> Search for the package named "UI") It's strange since it's also supposed to be a dependency of the Input System package.  Either way the UI elements are not really supposed to be used as-is, it's mostly an implementation example so you could just remove those files either way and use your own UI.

And the reason the type "Slider" is not recognized is most probably because you don't have the UI package not because I don't know how to type (Errors like that are usually caused by how your project is setup since Unity has a lot of package that can be enabled or disabled)

What exactly do you mean by "the UI package"? If you're talking about Unity UI, I installed it and still nothing. I have both UI and UIElements built-in and enabled.

I mean that if you remove "using UnityEngine.UI" from the file that use the type "Slider" it will cause issues either way because it's the namespace that contains the "Slider" type. 

Did you try to install my package on a new project? If you have Unity UI installed it should work. But it seems to be a common issue maybe you can find more info on how to solve that here https://forum.unity.com/threads/solved-the-type-or-namespace-ui-does-not-exist-i... 

(1 edit)

Ok, so after reinstalling the package, along with Unity UI and the other 2, it works without any errors. I don't know exactly how it worked, but apparently it just does lol

Either the package or Unity is running off some real spaghetti 

Deleted 73 days ago

If it helps by the way, I found multiple missing scripts in the "Player" "Enemy_Range" "Enemy_Contact" and "Player_Close" prefabs.

2022.3.9f

This plugin has only been tested up to Unity 2021, I'll try to look into what could be causing the issue and update it when I have time

hi, I'm also new to unity, I downloaded this asset and I have only 2 errors

this  first error

Assets\TopDownController2D\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(30,16): error CS1503: Argument 1: cannot convert from 'UnityEngine.Vector2' to 'UnityEngine.InputSystem.InputValue'

this second error

Assets\TopDownController2D\Scripts\TopDownCharacter2D\Controllers\TopDownInputController.cs(48,20): error CS1503: Argument 1: cannot convert from 'UnityEngine.Vector2' to 'UnityEngine.InputSystem.InputValue'

tell me how to fix it please

Hello, which Unity version are you using?

I don't seem to have any issue using Unity 2022.3, so please make sure that you :

  • Install the Input System and Cinemachine package (To install a package from Unity go to Window -> Package Manager -> Search for the name of the package and install the plugin (if you can't find it in the results make sure that you set the list of packages to display the content of Unity registry at the top left of the window))
  • Make sure your project uses the new Input System package (Edit -> Project Settings -> Player -> Other Settings -> Active Input handling -> Input System Package (new)

and restart the editor afterward, if you still face some issues try to re-import the plugin after that, if even after that it still doen't work, feel free to tell me

(1 edit)

Hey new to unity, why do i get an error when trying to Import this in?

"Assets\TopDownController2D\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?)"

"Assets\TopDownController2D\Scripts\TopDownCharacter2D\UI\EntityHealthGaugeUpdater.cs(4,19): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)"

"Assets\TopDownController2D\Scripts\TopDownCharacter2D\UI\EntityHealthGaugeUpdater.cs(13,34): error CS0246: The type or namespace name 'Slider' could not be found (are you missing a using directive or an assembly reference?)"

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

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

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

those are the errors in question.

(3 edits)

Hey, which Unity version are you using ? Also from what I see most of those error are caused by a missing dependency, the sample project use the new input system so it needs to be installed in the package manager and activated for those errors to go away https://docs.unity3d.com/Manual/com.unity.inputsystem.html

What license do the sprites fall into?

You can use them however you want without having to credit me, they where created solely for this project.

(+2)

I couldn't get it to work for a while because the new input system (even when assigning keys) wouldn't detect any presses, and playing wouldn't let me move or shoot.

The fix was: 

Edit -> Project Settings -> Player -> Other Settings -> Configuration, and set "Active Input Handling" to "Both"

It worked suddenly after restarting.

A very excellent work, Thanks.

Hello , thx for awesome pack , I am new Input sistem , If i wand player move where i clip Mouse , what do i need? thx

i'm unable to see where it explain how to switch to the sword hit, can u give me a hint ?

In the sample project you can look at the "Player_Close" game object (which is disabled by default), but in a general case you need to add a "Top Down Melee" component to your character (in which you will need to add a reference to a prefab containing a "Melee Attack Controller" component), and changes its "attack config" in its "Character Stats Handler" component to be a Melee attack config (in the sample project there is the "PlayerSwordSlash" config. I don't know if that's what you wanted. 

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.

You can code two joysticks and decide its movement by the left joystick and decide attack direction with a right joystick or vice versa.

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?)

(+1)

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