Unity Twin Stick Shooter Tutorial by Turbo Makes Games

February 3, 2021

Gamepad Joystick Inputs

Unity

Title:
How to Make a Twin Stick Shooter in Just 4 Hours – Unity Beginner Tutorial

By:
Turbo Makes Games


Youtube – Tutorial

Description:
Full tutorial on making a simple twin stick shooter in Unity.


Introduction

I was mostly looking for the basics of setting up twin stick shooter input controls in Unity, mainly with how to setup the second stick, and came across this full tutorial for twin stick shooters. I can use the player controller and input setup information to cover that for sure, and having access to the rest of the tutorial can be useful for ideas and concepts if I want to help flesh out my example.

Twin Stick Controls for Gamepad in Unity

To setup the right joystick for a gamepad in a project such as a twin stick shooter in Unity, you go to the “Project Settings” and go to the “Input” section. Here you can modify the list of inputs Unity is dealing with, so you can add the extra joystick. The easiest way to do this quickly for another stick is simply duplicating the default “Horizontal” and “Vertical” options and renaming them. Once renamed, just change their axis to 4th axis (for the x-axis of your right stick) and 5th axis (for the y-axis of your right stick). This should provide you the additional input options for the right stick of a gamepad.

via Blogger http://stevelilleyschool.blogspot.com/2021/02/unity-twin-stick-shooter-tutorial-by.html

Unity Input Action Assets Intro with InfallibleCode

October 26, 2020

Input Action Assets

Unity


Title:
Unity Input System | How to Use Input Action Assets

By:
Infallible Code


Youtube – Tutorial

Description:
One of the better tutorials covering all the basics of utilizing Unity’s new Input Action Asset for their new input system.


Tutorial – Part 1 – Reference by String

Initially there are already some issues since they are using an older version of the new Unity input system. GetActionMap and GetAction are no longer methods associated with the InputActionAsset object and the InputActionMap object. To get around this I just used the FindActionMap and FindAction methods and they appeared to work fine here.

There are to callbacks tied to the movement action we created: movement.performed and movement.canceled. According to the Unity documentation, performed means “An Interaction with the Action has been completed” and canceled means “An Interaction with the Action has been canceled”. Then there is a method named OnMovementChanged which reads the current context input from the Vector2 input and just assigns it to a Vector3 used for movement. Since this method subscribes to both movement.performed and movement.canceled, my understanding is that the OnMovementChanged method is then called with performed when an input is given (to start moving the player) and then OnMovementChanged method is called again through canceled when the player lets go of the input (so the system knows to stop the player or at least to assign a zero vector value).

The action map and actions are referenced here through strings. These strings are the names given to them in the input master you create initially. Also the inputs created for the Movement action they created use a 2D Vector Composite.

Tutorial – Part 2 – Reference Hard Typed Generated Script

After noting that the action map and actions must be referenced through strings in the initial project, they mention that there is a way to replace the string accessors with strongly typed solutions. They also mention to do this they would encapsulate the logic in a few methods and break them off into their own class, but this is where they introduce the Input Action Importer which can do that for you using the Input Action Asset you have created.

When selecting the Input Action Asset, there is a “Generate C# Class” option. This creates an “encapsulation of your Input Action Asset complete with strongly typed accessors for all of your custom made action maps and input actions.” When creating this, you are also given some options to define where the file would be saved, what it is named, and what namespace it should live in. Leaving these blank provides a default option. The older version also had check boxes for generating events and interfaces, but those do not appear in the newer version I am using.

Looking through the generated class, we can identify in the lines here where the strongly typed accessors have been created:



m_UnityBasicMovement = asset.FindActionMap(“UnityBasicMovement”, throwIfNotFound: true);

m_UnityBasicMovement_Movement = m_UnityBasicMovement.FindAction(“Movement”, throwIfNotFound: true);



Here…

UnityBasicMovement = name of the action map

Movement = name of the action (found within the UnityBasicMovement action map)

This then allows you to tie your actions into the Input Action Asset through an approach as follows:



movement = playerControls.UnityBasicMovement.Movement;



Here…

movement = an InputAction object

playerControls = reference to the generated C# script object from the Input Action Asset

UnityBasicMovement = name of the action map where the action is located

Movement = name of the action



This entire line of references are all now hard typed and help reduce errors.

I then ran into an issue I faced in another tutorial using an older version of this input system. They had a serialized field to drop a reference to the generated class into in Unity’s inspector, but that is not an option with the new system. To rectify this you just need to create a new instance of that generated class to connect all your actions to.

Tutorial – Part 3 – Use Generated Interface

Here they use the interface created by the generated class because they selected the “Create Interface” option. I see this interface structure is also present in the class I am working with so it appears that is just added by default now. This is important because the generated class also creates a struct with in it that holds a method that requires this interface as a parameter.

This method is named SetCallbacks. It takes in the generated interface (named I[Name of Action Map]Actions) and that parameter is named instance. It then checks if the wrapper.callbackinterface object has been set yet and if so, it unsubscribes all of its OnMovement methods from the action’s event (in this case, the Movement action). It then sets that wrapper.callbackinterface to the current instance for future reference, and adds all the current instance’s OnMovement methods to the Movement action (again, this is the started, performed, and canceled events). All in all this method handles unsubscribing everything from a previous instance (if there is one) and then subscribes all of the new instances methods (or just adds them if it is the first instance). They word it as “this method registers the instance of IGameplayActions to the Movement InputAction’s events: started, performed, and canceled.”

After making the player input script with all our movement logic implement this created interface, this means all of the manual method registering to events could be replaced with simply using the SetCallbacks method passing in this as the parameter. Make sure to use the method required by this interface (which was OnMovement in this case) and place your input logic into that method. Then finally the object that should be enabled and disabled at this point should be your InputActionAsset generated class, and not an InputAction object.

To summarize…

I replaced:



movement.performed += OnMovementChanged;

movement.canceled += OnMovementChanged;



with:



playerControls.UnityBasicMovement.SetCallbacks(this);



and replaced:



private void OnEnable()

{

movement.Enable();

}



private void OnDisable()

{

movement.Disable();

}



with:



private void OnEnable()

{

playerControls.Enable();

}



private void OnDisable()

{

playerControls.Disable();

}

Summary

This tutorial was extremely helpful for showing all the ways you can access Unity’s newer input system through C#. They start with the basic string references, then move to the hard typed option created by their generated class, and finally show how the interface within the generated script can be used to implement hard typed references as well. While it is a bit more complex to get started with this setup than Unity’s original input system, this tool seems like it could be very promising for quickly setting up more involved player controllers. It also looks like it will provide good options for editing the inputs at run time.

via Blogger http://stevelilleyschool.blogspot.com/2020/10/unity-input-action-assets-intro-with.html

Exploring Unity’s New Input System Further

October 15, 2020

Input System

Unity


Title: How to use the new Input System in Unity3D
By: Coding With Unity
Youtube – Tutorial #1
Description: Indepth tutorial on implementing Unity’s new input system along with programming its use.


Title: New Unity INPUT SYSTEM – Getting Started
By: Dapper Dino
Youtube – Tutorial #2
Description: Quick tutorial using Unity’s new input system and using it with programming.


UPDATE

Title: Unity Input System | How to Use Input Action Assets
By: Infallible Code
Youtube – Tutorial #3
Description: Good all around tutorial for getting started using Unity’s new input system.


Title: Unity Input System Quick Start Guide
By: Unity
Unity – Input System Documentation v.1.0
Description: Unity’s documentation on the new input system.


Overview

I have already tested using the new Unity input system a bit and it seems promising so I wanted to explore it further. These tutorials show it in use on a more in depth level so I expect them to show me some more ways to utilize it properly. The documentation was also included as it is useful to find any methods I may need to keep everything together and working.

Update

I found another good tutorial by Infallible Code that I have added. I think it covers the foundational work of using the new input system better than the other tutorials and gives a better explanation of what the generated class from the input system is actually doing. This makes using it much more sensible.

Resetting Keybindings with New Unity Input System

October 14, 2020

Rebinding Keys

Unity – New Input System


Overview

I have been trying out the new Unity input system to see if it is worth using instead of the older method of building out everything yourself. In this process I wanted to make sure it had a way to rebind keys since this is a gigantic feature to have in almost all games. I was able to find that there are several different ways to change keybindings with the methods found in Unity’s documentation on the new input system found here:

Unity Editing Keybindings for New Input System Version 1.0

The two main methods I am focused on currently are ApplyBindingOverride and PerformInteractiveRebinding. PerformInteractiveRebinding allows for keybinding modification by the player at runtime, and is a quick way to implement a feature commonly found in many games where the player selects an action to change the keybinding for and the game awaits their input to set the new keybinding to that input. I do not think this change is saved inherently however, which is where the other method comes in.

ApplyBindingOverride allows the system to override the default keybinds set by the game originally. So after using PerformInteractiveRebinding methods, that data can be saved to then later be utilized by the ApplyBindingOverride method to reapply the keybind changes every time the game is started. This helps it fall in line with how the feature is utilized in most games in a very convenient and user-friendly way.

Creating an Input Buffer System for an Action Game

October 13, 2020

Input Buffer System

Game Development


Title: Character Action Game Development Tutorial 8– Input Buffer
By: Tyra Doak
Youtube – Tutorial
Description: Small segment of a tutorial list that focuses on creating an input buffer system in a 3D action game.


Overview

Having input buffering in a game can help a game feel much more responsive and smoother to a player, especially in hectic, fast paced gameplay such as fighting games or action games. This tutorial has a large emphasis on building out their input buffering system for their 3D action game so this is right in the prime territory for the type of game I am interested in building an input buffering system for as well. They also show a decent visual display of the frame data at the top of the screen during play mode that could be an ok starting point to help with starting to build frame data focused systems.

Unity Create Your Own Keybindings Manager

October 5, 2020

Unity

Input Systems


Title: How to Create a Custom Keybinding Handler for your Unity Game – *Improved*
By: Dapper Dino
Youtube – Tutorial
Description: Tutorial for creating your own basic input manager within Unity.


Overview

The idea behind creating an input manager is to have a flexible and easily accessible tool for both setting up your input system within a game as well as modifying it. This manager should help keep programming associated with the player input more organized and consistent, as well as providing pathways to allowing both the designer and eventually the players options to easily change the inputs to their liking.

Tutorial Notes

Setup

Immediately they create an InputManager class that follows a singleton pattern, but also includes a DontDestroyOnLoad method. This is ok to start, but may be worth looking into editing that if using a more sophisticated multi-scene project setup later on.

Within the InputManager, they created classes to replace some of Unity’s basic input reading methods. These included: GetKey, GetKeyDown, and GetKeyUp.

They then added another class named KeybindingActions, which was a container for a public enum that held references to all the possible actions you may want for the game. For now I decided to just include this enum directly in the InputManager class, but will see if it makes sense to separate later.

Next they add the scriptable object core of this setup, which is named Keybindings. The benefit of using a scriptable object here is that it makes it easy to swap it out with different sets of keybindings (especially with different types of input or controllers).

Building Out InputManager and Keybindings Scriptable Object

Within this scriptable object, they created another class named KeybindingCheck. This provides the connection to setup which keys are tied to which actions. They mention a dictionary could be used here, but they created a list of this serializable class instead so it can easily be seen and modified within the Inspector. This class simply holds data for a KeyBindingActions object and a KeyCode object (to ensure they are connected). The scriptable object then just has a list of these KeyBindingChecks.

They mention if you want the player to be able to set their own keybindings you technically just need to edit the scriptable object and this will modify the keybindings. However, scriptable object changes only remain if they are done in the inspector, so you would also need to save that data somewhere else if you had a game where you want the player to be able to set their keybindings once and have the same setup each time they close and reopen the game, which would be the standard implementation.

With that setup, they go back to fill out the methods within the InputManager which effectively replace those provided by Unity. Each of them follow the same pattern seen here in the GetKeyDown replacement method:

public bool GetKeyDown(KeyBindingActions key)
{
foreach (KeyBindings.KeyBindingCheck keyBindingCheck in keybindings.keyBindingChecks)
{
if (keyBindingCheck.keyBindingAction == key)
return Input.GetKeyDown(keyBindingCheck.keyCode);
}

return false;
}

So effectively whenever you would use GetKeyDown for example, you use this InputManager.GetKeyDown method and pass in one of the enum options you have provided as a parameter (i.e. Jump, Crouch) and it searches through the list of KeyBindingCheck objects you have in the KeyBindings scriptable object and if it finds that enum in that list, it returns the Unity base input method (i.e. GetKeyDown here) with the corresponding keyCode you have associated with that enum as its input parameter.

Summary

I like that this method allows for the use of easily accessible and modifiable enums that are specifically chosen for your game when it comes to programming the input of your game, but I am concerned how efficient this is since it appears to add small extra checks with every single input from this user. While small, this is an extremely common action that will be used thousands and thousands of times easily in normal gameplay so I wonder if it ends up being worth the cost. This method does also allow you to edit the keybindings at runtime and because it is with a scriptable object, the changes are actually saved even when exiting play mode.

Newer Unity Input System

October 5, 2020

Unity

Input Systems


Title: NEW INPUT SYSTEM in Unity
By: Brackeys
Youtube – Tutorial
Description: Tutorial for using Unity’s newer input system.


Overview

This setup uses Unity’s improved new input setup system. It provides a nice way to setup your inputs more specifically without directly going into the Project Settings -> Input Manager window. The user starts with a blank slate and adds actions to this input manager asset to match up with all the actions they will want in the game.

From this tutorial they obtained the tools to use this new input system through a project on github, but now it is available as a standard package within Unity simply named Input System. It however mentions that the backend has been modified (I am using Unity version 2020.1.5f1 currently when testing this) so I am keeping an eye out for any problems it may cause.

Tutorial Notes

There are three major sections to this input system: Action Maps, Actions, and Properties. The action maps appear to be like keybinding sets, so you can save entire different sets of actions with their own keybindings to each map you create. Then the actions are the core focus, where actions can be named and keybindings can be set, as well as which types of controllers are used. Finally the properties section allows for more detailed additions to each action such as other modifiers to apply to the input when used as well as the type of action.

After filling this out to the desired result, there is an option to “Generate a C# Class” from this new input system you have created. This provides you with the proper tools to utilize the asset you created within your programming system yourself. The context is a bit more awkward as it uses events, so you have to assign methods to them when using them in your own programming. They set this up in the Awake method for example:

controls.Player.Shoot.performed += _ => Shoot()

controls is the name of the InputMaster object (which is what they named the generated C# file from the input system), Player is the name of the action map, shoot is the name of the action from the input system, performed is a subset of that action, and finally Shoot is the method being subscribed to that event. The underscore is simply a place holder used for this programming syntax so it is necessary but I am unsure exactly why the syntax is like that.

I was then having an issue following the tutorial because they simply made controls (their InputMaster object) public so they could drag/drop the input system asset itself directly into the component so they were connected and running. When I did this the InputMaster object did not show up in my Inspector, even when made public. To get it to work at all, I found that I just needed to assign a new InputMaster to controls in the Awake method. I found that in the documentation provided here: Unity New Input System Manual

I then found that natively you could not use both the old input system and the new input system at the same time. So while this did get the new input system working and I could jump (which was the only action I assigned for testing), I could not move horizontally at all as the inputs for that just did not work anymore. Exploring the documentation further, I did find that you can switch back and forth between the old and new input system, as well as activate both at the same time, in the: Project Settings > Player, under: Active Input Handling. Upon setting that to both, I could move horizontally (with the old inputs) and jump (with the new inputs).

Installation Guide here: Unity New Input System Installation and Setup Documentation

Summary

This approach seems promising for setting up complex keybinding setups where you also want multiple devices. It does provide the base benefit of not needing to use strings with the input system anymore when doing the programming so that is a large benefit already. I would have to explore how to edit keybindings at runtime with this setup to see if it is a good final approach for this system that would also support letting the player set their own keybindings.