Forum rules - please read before posting.

Mobile joystick

Hi all,

I have created a character with mobile joystick controls for mobile games. It has movement joystick and camera joystick. The movement joystick can move character and the camera joystick can also move the camera.

However, with the camera joystick, any movement outside of the joystick, the player also moves. I want to lock this into joystick control only and not the UI screen. How do I go about this?

My interface setting is:
Movement method: Direct
Input method: Touch Screen
Interaction method: Context Sensitive

I tried first person movement and that locks the camera within the joystick control but the movement joystick will not move the character.

Any assistance would be appreciated.




  • What are your Unity/AC versions, and what camera type are you using, and what inputs are you mapping both joysticks to?

    However, with the camera joystick, any movement outside of the joystick, the player also moves. I want to lock this into joystick control only and not the UI screen.

    I'm not clear on what you mean by this. Can you share an annotated screenshot to elaborate?

    If you set the Movement method to First Person, then additional options will show when using touch-screen input. Setting the First-person movement field to Custom Input will let you override input via joystick controls: player movement is handled by overriding Horizontal and Vertical, while free-aiming is handled by overriding FreeAimDelegate.

    See the Manual's "Remapping inputs" chapter for an overview of this topic, but essentially the free-aim delegate refers to a custom script function of the form:

    private void Start ()
        AC.KickStarter.playerInput.InputGetFreeAimDelegate = FreeAimOverride;
    private Vector2 FreeAimOverride (bool cursorIsLocked)
        return myCustomInputVector;
  • Hi Chris,

    This video record will explain it better.

    Im using Unity v.2019.3.0f1
    AC: v1.70.0

  • The video is set to private - I can't view it.

  • I have unlisted it. Try now.

  • I see. If you're not looking to make a first-person game, don't use First Person movement.

    Again, what camera type are you using, and what inputs are you mapping both joysticks to? If you are relying on any custom scripts / separate assets, please elaborate.

    It looks like this may be just to do with the way your joysticks are set up - seems that the left joystick also only moves the player when it is outside the graphic's boundary.

  • Actually, it is first person game. I didnt change the camera setting to make it fps during the recording.

    Im using 3rdPerson + Fly(Mobile) asset. Without AC, it functions beautifully. When I start making a character with AC's wizard, this is where the problem occurs.

    Camera, I'm using Default Camera attached to 3rdPerson Main Camera. I havent changed any settings from using 3rdPerson and Fly asset.

    See this new video showing of the asset as is without AC's Character wizard.

  • If you already have a character / camera controller setup without AC, you should be able to override AC's own control systems in favour of one you're already happy with.

    Leave your Movement method as Direct, and attach a Basic Camera component to your custom camera - that way you can assign it as the scene's default in the Scene Manager.

    Attach a Player component to your character, but set the Motion control to Manual - this will cause AC to rely on any custom scripts attached to affect his motion. See the Manual's "Custom motion controllers" chapter for more details on how this works.

  • Okay thanks Chris will work it out using the Custom motion controllers.

  • I tried using the motion control tutorial. Not sure how I should call the VirtualButtons script to bridge/link it with AC's system.

    So far, I can play my game but it will only be one or the other. Need to link them together as I prefer to control the player within the virtual input and allow the player to pathfind objects and travel automatically to that spot (marker).

    Not sure if I am making any sense lol.

  • You can dynamically switch the Player's "Motion control" field between "Automatic" and "Manual" modes through script - so that he can rely on AC motion during e.g. cutscenes.

    This is mode easily done from an Update loop:

    private void Update ()
        if (!KickStarter.stateHandler.IsInGameplay () || characterAC.IsMovingAlongPath ())
            KickStarter.player.motionControl = MotionControl.Automatic;
            KickStarter.player.motionControl = MotionControl.Manual;

    Though I understand you're using your own system for driving motion, I should mention that it's still possible to rely on just a joystick asset to still rely on AC for everything else - see this page on the wiki as an example.

  • Ok thanks for your reply. That sure does look cleaner to implement. I wonder where do I put this update loop in the player.cs? When I put that method (the above script) into the player.cs script anywhere, it doesn't recognise the characterAC shown in the above script.

    Re: Simple Touch Controller, I have tried it. Bit glitchy though and I don't like its simple virtual joystick outlay. This is why I am trying to implement the 3rdPerson+Fly asset. I also enjoy its fly and jump mode buttons.

  • The code can go in a separate script, attached to the player.

    Replace "characterAC" with "KickStarter.player".

  • Okay that's kind of working now. However, the left joystick is not moving the player. The right joystick is moving the cam beautifully.

    What it seems to be is the player.cs when its switched on, the left joystick doesn't work, however, the playerobject is able to pathfind automatically to the marker.

    When switched off, both joysticks do work but the pathfind to marker is not working. I think what is needed is something that switches on and off the player.cs.

    For instance, when playing the game, the player.cs is not switched on. This is so the virtual joystick operates as expected. Upon clicking on a hotspot and prior to going to a selected marker, the player.cs is switched on so it can pathfind towards the marker. Once the actionlist is completed, the player.cs will be switched off so it goes back to its joystick motion controller and the player is able to continue moving around smoothly with my preferred virtual joystick.

    Would this be the correct way of doing it? If so, how do I go about this?

    I appreciate your help here.

  • Here's a screen-recording of my player.cs on and off and how it impacts the joystick controls or the pathfind.

  • edited January 2020

    When the Player component is active, and the "Motion control" field is set to "Automatic", it will override motion from other scripts.

    When set to "Manual", however, you should be able to have it enabled while other scripts control position/rotation.

    For AC to be able to correctly direct the Player along a Path, the Player component needs to be active at all times. This is the purpose of the above code - to allow it to be active, but in Manual, mode, when navigating via the custom motion controller - and then switch to Automatic mode when AC-pathfinding.

    Try keeping the Player component enabled, and change the Inspector field yourself to see what I mean.

    The "Motion control" field is not changing during the video. Did you use this code in a script attached to the Player?

  • Hi,
    I have included the motion control script (named as Control Interchange). I can see in the animation engine changing from manual to auto and vice versa. However, the player object will not move along the path. It only moves when I change the animation engine to Mecanim or Sprites Unity Complex.

    What am I missing here to get the player object to move along the path? I do have the NavMeshAgent and NavMeshAgent Integration applied to the player object.

    See the video.

  • Does your Animator rely on Root Motion? If so, animation and motion are directly linked, so Automatic motion can only occur if AC has control over the Speed parameter, which is done via the Mecanim engine's "Move speed float" field.

    You can either look to disable root motion in your animations, or change the "Animation engine" property in the "Control Interchange" script as well:

    private void Update ()
        if (!KickStarter.stateHandler.IsInGameplay () || KickStarter.player.IsMovingAlongPath ())
            KickStarter.player.motionControl = MotionControl.Automatic;
            KickStarter.player.SetAnimEngine (AnimationEngine.Mecanim);
            KickStarter.player.motionControl = MotionControl.Manual;
            KickStarter.player.SetAnimEngine (AnimationEngine.Custom);
  • Thank you Chris. Working superbly now.

    The disable root motion didn't do the trick but the new script addition worked.

  • Hi,
    The new motion control (Controller Interchange) script seems to work very well. It changes the animation settings from Custom/Manual to Mecanim/Auto upon hitting a hotspot and pathfind.

    However, when I move to a new scene and come back to the previous scene, the animation settings goes to from Custom/Manual to Custom/Auto. This makes the player object walk straight and not able to turn sideways or go backwards. Even if I move my camera around, it will only go in the direction it was set.
    Also, when I export it or build it into APK for mobile, it automatically starts off as Custom/Auto.

    How do I prevent the animation setting’s motion control flipping from Custom/Manual to Custom/Auto for no reason? The script should not allow that to happen but it does. Seems like something's overriding it.

  • The NavMeshAgent Integration script overrides the motionControl field - I should have spotted that.

    This script is designed only as its own motion controller - and only used with the NavMesh Agent. However, it's also designed to be self-contained - meaning you can duplicate it and modify a copy of it without it affecting AC itself.

    Try instead a copy that has it's calls to the motionControl field removed.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.