Tutorial Tuesday! No-Code Touch Controls! Unity Dual FPS Touch Joysticks

By | March 22, 2016

For a transcript of today’s broadcast… scroll down.

This video results from several issues: first and foremost, my Udemy students have asked me how to get touch controls to work. Secondly, I’ve seen yet another youtube video giving faulty information on the subject. Thirdly, I impulsively purchased Easy Touch 5 : Touchscreen and Virtual Controls. I was, in part, mislead by the Virtual name and thought that it contained additional Playmaker Actions for VR. This is not the case. Moreover, the particular functionality that I needed can be had for free using Unity’s standard CrossPlatformInput Package. I requested a refund from the Hedgehog Team but that has not been forthcoming. So, you can learn from my mistake and save yourself $35 by watching this video.

I’ve opened up the section3 Scene from the Get To Tha Choppa Project that accompanies my Udemy video course and my No-Code book. You get all this and all the art assets with either the video course or the book. In order to prepare the original Project for touch input there are two options; import a number of (unsupported) Packages into the current course Project or migrate to Unity 5 to take advantage of its native support of the necessary functionality. Check the nickelcitypixels.com blog for instructions as to how to migrate. We’ll be working in Unity 5.3. You can of course follow along in your own Project. You’ll need to have an FPSController in your scene.

Additionally I’ve imported the CrossPlatformInput package, right here, it’s a Standard Package. I’ve switched from the PC platform to Android and I clicked Switch Platform. And I’ve checked to make sure that Mobile Input is Enabled.

Now let’s open up Standard Assets>CrossPlatformInput>Prefabs. Select MobileSingleStickController and drag and drop it into the Heirarchy. Add an EventSystem. That’s it! That’s all you need to get your character moving around via touch joystick! That’s because it is engineered to tie into the existing FPSController and InputManagement system. Now, the problem is that the character can move around, but can’t look around.

In the aforementioned quote unquote faulty video the speaker spends a good deal of time programming and wrestling with Euler (Oiler) angles and all of that’s unnecessary if you understand how Unity’s Input system works.

So let’s talk about Unity’s Input system. I’ve yet to see anyone explain this satisfactorily. Unity’s InputManager pairs with its controller Prefabs (for example FPSController) and scripts (aka Components) to provide the developer with a behind-the-scene solution to game interfacing. Essentially what it does is open up its Controller and Input scripts so that some of the parameters can be edited in the Inspector through the InputManager. Let’s look at the InputManager now. Edit>Project Settings>Input. We see that the InputManager opens up in the Inspector View. Some things will be familiar already. You can see that there is a field in which to specify how many Input Parameters there are in Size. Now, notice, it is curious that many of the parameters repeat or are otherwise duplicated. Most people will notice that but tune it out. Don’t. You should explore anything that gets your attention, so let’s do that now.

Let’s look at the first Horizontal and compare it with the second Horizontal. By looking at it we can ascertain that somewhere there is a script with the magical word Horizontal that is responsible for moving the character left and right, that is, in the x axis. We can also surmise that we can edit what inputs the player uses to make that happen. Again, InputManager allows us to do that here without having to tinker with the code. We see that Type is significantly different between the first Horizontal element and the second Horizontal element. The first Type is specified as “Key or Mouse Button” and the second Type is specified as “Joystick Axis.” So what’s going on here is that the Project is set up to use multiple controller types simultaneously. You don’t have to specify whether the player is using a keyboard or physical joystick or touch joystick. The game will allow the player to use any or all of these controller schemes so long as the proper Components are in place. Let’s look at the MobileJoystick GameObject’s Components. In the Joystick (Script) Component, we see that Horizontal Axis Name and Vertical Axis Name have been specified as the magical words we recognize from the InputManager, Horizontal and Vertical. So this joystick is set up to move the character forwards, bacwards, left, and right.

How do we get the character to look around? Well, how did we get the character to look around in the PC version? With the mouse. And are there mouse input elements in the InputManager? Let’s look. Yep. They are called Mouse X and Mouse Y. So let’s duplicate the MobileJoystick Prefab and swap out the Horizontal and Vertical Axis Name parameters for Mouse X and Mouse Y. Move the joystick over and tada, that’s all there is to it. Fire is already tied into tapping so that’s already been taken care of for us. We’re done. Sure beats wrestling with code and Oiler angles.

You can test it out in Play Mode but I can’t because I’m running a very weird KVM setup. I might edit in some screen records from my Android, I might not, but trust me it works. If you’re interested in additional No-Code solutions, including how to create an entire FPS Horror Survival game, check out my Udemy course, my blog, and or my book being published through Taylor and Francis. Links in the description. Hope this helped! Thanks!

 


A Note from Admin:


I hope you found this content useful. If so, please like and subscribe and consider contributing to

so that I can continue to produce great #gamedev and #game art content while battling cancer!

Subscribe and get ahead with the latest tech recommendations, tricks, and tutorials!

Or subscribe to:
NCP on Twitch
NCP on YouTube
NCP on Twitter (warning: politics!)

WIP Sites:
learnindiedev.com Unlike Udemy, this site will feature live lessons and game jam learn-a-thons (exactly what it sounds like)! Featuring No-Code Video Game Development, the only video course to become a published text book!

openforcommissions.com Why be hard to find? Upload your portfolio, change your open/close status with a single tweet, get paid!

2 thoughts on “Tutorial Tuesday! No-Code Touch Controls! Unity Dual FPS Touch Joysticks

  1. mike

    I have the book No Code Video Game Development Using Unity and Playmaker and have been trying to contact the author. The book invites contact but gives no way of doing it. I have a problem where the first level will not run because of a script error. How can I contact Mike Kelley to ask for help please?
    Thank you
    Mike

    Reply
    1. admin Post author

      Hi Mike,

      Sorry I haven’t responded sooner but cancer treatment has been taking up all my time, I’m just now seeing your comment. I’ve sent you an email. Hopefully I’ll be able to help you sort out the error. Thanks.

      Mike

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.