Forum rules - please read before posting.

Controller and touch screen controls at the same time

Hi, I seem to have encountered a road block when developing a game for a certain platform that allows for both controller input and touch screen controls.

I'm using Rewired to map controls to the gamepad, and using the script found at
https://adventure-creator.fandom.com/wiki/Rewired_integration
makes this work well.

Movement method is Point and Click, and when I use the Keyboard and Controller input method, I can control the cursor with my gamepad and interact with objects with the buttons. However, this input method does not work well with a touch screen, since this (as far as I understand how rewired works) makes the cursor rely on simulated horizontal and vertical axis. This means that the cursor is offset and does not follow the speed or the positioning of the system (this is the same when using a mouse as well).

Using the Mouse and Keyboard input method makes touch screen controls perfect, but this makes the cursor not controllable by the gamepad. However, all other buttons on the gamepad works. Available inputs listed by AC include CursorHorizontal(axis) and CursorVertical(axis), but these seem to not work in this mode?

I've read some other threads here on switching between these two input modes, but in my case I need them to work at the same time (seamlessly and without having an option in a menu to switch between them). So what I'm asking is; Is there a way to make the cursor controllable by a gamepad in Mouse and Keyboard mode?

I'm using latest AC and Unity 2018.3.

Comments

  • edited June 22

    I think I managed to get something working, and for others in the same boat this might be helpful:

    I switched to Keyboard and Controller input, and added these lines in the Rewired Integration script in an update function:

    `
    if (Input.touchCount > 0)
    {
    AC.KickStarter.settingsManager.inputMethod = InputMethod.TouchScreen;
    Touch touch = Input.GetTouch(0);
    if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(0).phase == TouchPhase.Moved)
    { // If the user puts her finger on screen and/or moves it, update the cursor to follow the finger position
    AC.KickStarter.playerInput.SetSimulatedCursorPosition(touch.position);
    }
    }
    else
    {
    AC.KickStarter.settingsManager.inputMethod = InputMethod.KeyboardOrController;
    }

            if (Input.GetMouseButtonDown(0))
            {
                AC.KickStarter.playerInput.SetSimulatedCursorPosition(Input.mousePosition);
            }
    

    `

    Now the cursor follows touch/drag and controller, and the last mouse check makes it also work when testing on PC (the cursor is offset, but snaps to the mouse position when clicked).

    EDIT: code formatting doesn't like my code :)

  • Code formatting just requires at least one indentation for all lines.

    For the sake of completeness, you can also adjust the speed of the "simulated" cursor speed via:

    AC.KickStarter.playerInput.cursorMoveSpeed
    

    You can also configure this directly in the PlayerInput component, which is attached to the GameEngine.

    It's also usually best to rely on each of AC's dedicated "Input method" options as appropriate, but you can change this through script too:

    AC.KickStarter.settingsManager.inputMethod
    

    Just right-click any Manager field label to get an API reference to it. You could, for example, read Unity's Input.touchCount property to determine how the player is currently interacting with the device.

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.