Search Unity

Virtual Joystick + Keyboard WASD

Discussion in 'General Discussion' started by hec031, Aug 22, 2019.

  1. hec031

    hec031

    Joined:
    Jun 5, 2015
    Posts:
    9
    Apologies, if this is been answered before but I could not find it if it exists.

    My issue is that I'm trying to have dual input controls, but not from a real joystick but from a virtual joystick and keyboard WASD control. Been trying to combine the two but I can't seem to figure out the proper way to write the code.

    Any help is appreciated. I just need a reference to a solution and I can probably figure it out from there.


    Thanks,
     
  2. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,023
    If you are trying to do anything with input, grab the Rewired asset. This is the most powerful and most flexible solution for input right now. It supports every form of input, including virtual joysticks. One of the sample scenes included with the asset is for virtual joysticks.

    https://assetstore.unity.com/packages/tools/utilities/rewired-21676
     
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,162
    What have you tried and why hasn't it worked? What platforms are you targeting? How are you getting the virtual joystick input and how are you getting keyboard input?
     
    angrypenguin likes this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Generally you have a method you call when you want to move the character which has nothing to do with input. Then separately you write an input handler script for keyboard, and have an input script for your virtual joystick. Those input scripts handle the input part of course, and then just call that first method for moving the character.

    If you try to combine taking input and acting on input into the same method, that's probably where you're running into confusion, as that can get messy.

    Slightly off topic, splitting the movement code from the input code also has the benefit of making it really easy to later implement AI based movement controls over the character. The AI script can just call the same movement code which the input scripts call.
     
    sulebugra and angrypenguin like this.