Mobile Controls

You are here:
← All Topics
Version: 2019.200 Requirements:uMMORPG3d, ToolsScript Define:_IMMOMOBILECONTROLS
Core Changes:YesTutorial Video:No

Description

Adds a on-screen joystick and shortcuts as well as a mobile camera and touch controls to your game.


Core Changes

  1. [Required] Open the following script UIShortcuts.cs. See Changes...

    Locate this line:
    quitButton.onClick.SetListener(() => {
                    NetworkManagerMMO.Quit();
                });

    Modify to match:

    quitButton.onClick.SetListener(() => {
                    NetworkManagerMMO.Quit();
                });
    			Utils.InvokeMany(typeof(UIShortcuts), this, "Update_");
  2. [Required] Open the following script Player.cs. See Changes...

    Locate this line:
    	// simple tab targeting
        [Client]
        void TargetNearest()
        {
            if (Input.GetKeyDown(targetNearestKey))
            {
                // find all monsters that are alive, sort by distance
                GameObject[] objects = GameObject.FindGameObjectsWithTag("Monster");
                List<Monster> monsters = objects.Select(go => go.GetComponent<Monster>()).Where(m => m.health > 0).ToList();
                List<Monster> sorted = monsters.OrderBy(m => Vector3.Distance(transform.position, m.transform.position)).ToList();
    
                // target nearest one
                if (sorted.Count > 0)
                {
                    SetIndicatorViaParent(sorted[0].transform);
                    CmdSetTarget(sorted[0].netIdentity);
                }
            }
        }

    Modify to match:

    	// simple tab targeting
        [Client]
        void TargetNearest()
        {
    		if (Input.GetKeyDown(targetNearestKey)
    			
    			#if _FHIZMOBILECONTROLS
    			|| targetButtonPressed) {
    			targetButtonPressed = false;
    			#else
    			)	{
    			#endif
    			
                // find all monsters that are alive, sort by distance
                GameObject[] objects = GameObject.FindGameObjectsWithTag("Monster");
                List<Monster> monsters = objects.Select(go => go.GetComponent<Monster>()).Where(m => m.health > 0).ToList();
                List<Monster> sorted = monsters.OrderBy(m => Vector3.Distance(transform.position, m.transform.position)).ToList();
    
                // target nearest one
                if (sorted.Count > 0)
                {
                    SetIndicatorViaParent(sorted[0].transform);
                    CmdSetTarget(sorted[0].netIdentity);
                }
            }
        }
  3. [Required] Open the following script Player.cs. See Changes...

    Locate this line:
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");

    Modify to match:

    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    
    #if _FHIZMOBILECONTROLS
    horizontal += MobileControls.joyVirtualAxis.x;
    vertical += MobileControls.joyVirtualAxis.y;
    #endif

Installation

  1. [Required] Delete or comment out the original “CameraMMO.cs” file and use the provided one (many core changes).
  2. [Required] Carefully apply all core changes as described above (quite a few on Player.cs).
  3. [Required] Add everything from this AddOns “UI Prefabs” folder to your Canvas.
  4. [Required] Check the missing script on “UCE_UI_MobileControls” and assign your Skillbar UI to it (remove the missing script). It depends if you use original skillbar or the skillbar replacement AddOn.
  5. [Optional] “UCE_UI_MobileControls” will only show up on mobile platforms, tick the “always active” checkbox to have them show up everywhere instead.
  6. [Optional] There are two basic potions that can be linked in the shortcuts, you find them inside the “UCE_UI_MobileControls” prefab to edit.
  7. [Optional] You can use the original skillbar if you want, by deactivating the new mobile skillbar inside the “UCE_UI_MobileControls” prefab. But it’s recommended to go with the mobile skillbar instead.

Screenshot


Extra

  • If you just want to have camera look with touch – you are done with importing the asset! Drag one finger on your touch enabled device to turn camera, pinch with 2 fingers to zoom and tap to move to position/select entity

  • If you want a virtual joystick for movement and a virtual button for targeting enemies, simply drag the “MobileControls”* onto your Canvas. By Default the joystick will be placed in the lower left side of the screen, so you might want to get some space there – i.e. you can move the Chat to upper left of screen and HealthMana to lower center. Control the as described above, either while using joystick or not – you can still tap to move.

  • For a better reachability of Skills (like Attack) or item (potion, equipment, etc.) on smaller screen, just drag the “Skillbuttons” prefabs onto your Canvas – be careful that it is above Shortcuts in Hierarchy. The big button in lower right is always the Default attack, the 2 small ones are meant for consumable items, like potions, default is Health Potion and Mana Potion. You can define them to other potion items in Inspector (drag preferred ScriptableItems to slots “Consumable Item 1” & “Consumable Item 2”) – the Default Skillbar will autohide on start if Skillbuttons are in your Canvas.

  • Now you might see that the Shortcuts bar is right above the Skillbuttons, to solve this problem you can add a Show and Close Button. Therfore find ButtonClose and ButtonShow Prefabs in the AdvancedMobileControls folder. Then drag ButtonShow directly onto Shortcuts and ButtonClose onto ShortcutsPanel. After that select the Shortcuts and in Inspector you should see 2 free slots: “Show Button Object” -> there you connect the ButtonShow and “Close Button” -> there you connect the ButtonClose. If you know start the game, the Shortcuts get hidden by default and only show up, when you press the new ShowButton (looks like Burger Button) – to close Shortcuts again, press the similar looking button in the Shortcuts panel.

  • Feel free to play around with different layouts of the controls, i.e. you can set the Shortcutspanel to vertical, (find “Grid Layout Group (Script)” in Inspector), there set the Constraint to “Fixed Column Count”.

Support the IndieMMO Team Today!

Leave a reply

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