Search Unity

Simple Input - use custom input providers like joysticks, UI buttons and d-pads [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Mar 5, 2018.

  1. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
    [QUOTES="yasirkula, post: 6048794, member: 56169"]Perhaps somehow Unity's Input.GetAxis is triggered by your touchs and it in turn triggers SimpleInput.GetAxis. You can use a custom axis like "Horizontal2" instead of the built-in ones ("Horizontal"). Alternatively, you can set SimpleInput.TrackUnityInput to false on Android devices so that Unity's Input.GetAxis doesn't trigger SimpleInput.GetAxis on those devices.[/QUOTE]



    Thanks a lot but please how can I do this , I'm not a very experienced programmer.
    They problem occurs when I try to to press two buttons simultaneously . Like thrust button and Right button. Then the left button triggers itself automatically and spontaneously.
     
    Last edited: Jul 3, 2020
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Inside Awake or Start function, you can add this code:

    Code (CSharp):
    1. #if !UNITY_EDITOR && ( UNITY_ANDROID || UNITY_IOS )
    2. SimpleInput.TrackUnityInput = false;
    3. #endif
     
  3. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9

    Thank you very much. I tried both solutions but unfortunately no progress
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Is the left button in the middle of thrust and right buttons? Did you perhaps add another SimpleInput component to right button or thrust button by mistake (e.g. Touchpad component, a second Axis/Button Input UI component)?
     
  5. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9

    I've finally figured it out .
    I was running the plug-in along with the "NEW UNITY INPUT SYSTEM" all I had to do was remove it and everything works flawlessly. Thanks a lot for your help.

    PS: the NEW UNITY INPUT SYSTEM HAS A LOT OF BUGS" so if you're not a very experienced programmer I wouldn't advice you use it.
    My first encounter with it has been frustrating. E.g the OnScreenControls fails spontaneously after building on android and this pushed me to use the Simple Input as an alternative, and I'm glad it did.
     
    yasirkula likes this.
  6. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
    I've finally figured it out .
    I was running the plug-in along with the "NEW UNITY INPUT SYSTEM" all I had to do was remove it and everything works flawlessly. Thanks a lot for your help.
     
  7. Emre009

    Emre009

    Joined:
    Jul 21, 2020
    Posts:
    4
    Hi, your asset is all i need to implement my game to the mobile platform but i am having issues with it. I use getaxis function to add force to my car object and change pitch of the sound files, but simpleinput.getaxis function is not working as great as the built in getaxis function.
    For example when i give 30 point acceleration to an object of 80 point mass,built-in get axis method works exactly in a way that i want,but the simple input version get stuck at lower turtle like speeds and never accelerate. But when i add some initial velocity to the object with built-in getaxis function, somehow simpleinput.getaxis starts to work as how it should work. This problem occurs when the object has speed of zero. SimpleInput axis buttons work correctly and return values like -1,+1,but somehow buttons don't work to add enough initial velocity to object. I use built-in physics so functions are all invoked in FixedUpdate method,might this be the issue? Are there anything like Response speed variable like in crossplatfrominput asset in the codes that i can tweak? I am not knowledgeable enough on coding and unity api to find out the source of the issue, so any help is appreciated.

    Bu arada Allah razı olsun hocam bu asset için,cennetlik iş resmen. Bayağı bi emekten kurtardın benim gibi çulsuzları. :D
     
    yasirkula likes this.
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  9. terricone

    terricone

    Joined:
    Nov 2, 2014
    Posts:
    4
    Hi. Your asset is very good. I have a strange situation with my steering wheel. Your web demo is working well with the steering wheel but in the Unity, the steering wheel is not working with the sample scene. It` Unity 2019.3 version. Can you help me? Maybe it`s the Project Settings problem?
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I couldn't reproduce the issue. If you haven't modified the sample scene, then I'd recommend you to check if Active Input Handling is set to either "Input Manager (Old)" or "Both" in Player Settings.
     
  11. terricone

    terricone

    Joined:
    Nov 2, 2014
    Posts:
    4
    Thank you! I will chek it.
     
  12. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
     
  13. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
    What if you want to do a swipe up and swipe down control to go up and down?
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can add multiple gesture components to the same RectTransform, if that's what you are asking. One can detect swipe up and the other can detect swipe down.
     
  15. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
    Ok but I'm not sure how to specify which swipe the ButtonInputSwipeGesture.cs should detect please advice. Thanks.
    I hooked up the script to a panel which has a rect transform and I don't know what else to do.
     
    Last edited: Aug 29, 2020
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Attach 2 ButtonInputSwipeGestures to the RectTransform. Set the first one's Swipe Amount to (0,20) and Button to UpArrow and the second's Swipe Amount to (0,-20) and Button to DownArrow.
     
    Clintelex likes this.
  17. Clintelex

    Clintelex

    Joined:
    Sep 22, 2018
    Posts:
    9
    Thanks so much for your help, it worked. And I ended up using the AxisSwipeGesture.
     
    yasirkula likes this.
  18. kallais

    kallais

    Joined:
    Jun 3, 2019
    Posts:
    11
    Hi, so I am creating a car racing game where the default keyboard steering is 'horizontal = Input.GetAxis("Horizontal");'. Now i want to use UI buttons with left and right buttons. How do i set these buttons to do what the keyboard does but on UI buttons?
     
  19. kallais

    kallais

    Joined:
    Jun 3, 2019
    Posts:
    11
    Wow. So I managed to solve my above problem by attaching the 'AxisInputUI' to say, my 'left' UI button and changed the default 'horizontal = Input.GetAxis("Horizontal");' to " horizontal = SimpleInput.GetAxis( horizontalAxis );". This solved the problem, now the car moves left when the left UI button is pressed. However, it "snaps" from 0 to -1 at once, unlike the keyboard ('horizontal = Input.GetAxis("Horizontal");') which smoothly transitions from 0 to -1. Well, i modified the Onpointerdown() to something like this:

    =============================================================================
    public void OnPointerDown( PointerEventData eventData )
    {
    axis.value = Mathf.MoveTowards(value, axis.value, sense * Time.deltaTime);
    // axis.value = value ;
    }
    =============================================================================

    And that pretty much solved the problem. It is amazing how you made such a useful asset to be FREE. I have been stuck at this problem for like 24hrs now but you saved me. Thanks a million.
     
    yasirkula likes this.
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Happy to hear that! SimpleInput.GetAxis actually transitions the value smoothly, as well. Perhaps its lerp parameter (which can be modified via SimpleInput.AxisLerpModifier) was too high in your case. You may also want to give the steering wheel prefab a shot, it can be fun in driving games ^^
     
  21. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    upload_2020-11-6_22-40-3.png
    Hi, how can I track a tap on the Touchpad? What's in the photo doesn't suit me. I need this so I can turn the camera around
     
  22. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    I need something like this mOrbitMode = SimpleInput.GetMouseButton(0);
    only based on the touchpad
     
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can add a MouseButtonInputUI component to the Touchpad, as well.
     
  24. robert12342

    robert12342

    Joined:
    Jun 11, 2018
    Posts:
    29
    many thanks, you asset best)
     
    yasirkula likes this.
  25. unity_9delizama

    unity_9delizama

    Joined:
    Dec 5, 2019
    Posts:
    2
    Hello, I have been using this plug-in and everything works great. However I have a problem when using the event system with this. So, I extended the BaseInput script, so it calls SimpleInput buttons and axis, and not the Input ones. The code is like this:

    Code (CSharp):
    1. public class CustomBaseInput : BaseInput {
    2.  
    3.     protected override void Awake () {
    4.         StandaloneInputModule standaloneInputModule = GetComponent<StandaloneInputModule> ();
    5.         if (standaloneInputModule) standaloneInputModule.inputOverride = this;
    6.     }
    7.  
    8.     public override float GetAxisRaw (string axisName) {
    9.         return SimpleInput.GetAxis (axisName);
    10.     }
    11.  
    12.     public override bool GetButtonDown (string buttonName) {
    13.         return SimpleInput.GetButtonDown (buttonName);
    14.     }
    15. }
    The method GetButtonDown works fine, but the GetAxisRaw works strange. The movement in the menus is a lot slower than using simply the unity Input class. Is there a fix to this? I am using Unity 2019.3.15f1
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can use SimpleInput.GetAxisRaw there. Hope it resolves the issue.
     
    unity_9delizama likes this.
  27. unity_9delizama

    unity_9delizama

    Joined:
    Dec 5, 2019
    Posts:
    2
    Oh I am so stupid, this works perfectly! Thank you for the quick reply :).
     
  28. Ill-Fish

    Ill-Fish

    Joined:
    Aug 23, 2015
    Posts:
    22
    I have a similar problem. I use the Button Input Keyboard script, selected "Right Control" as key, but I don't know what to enter in the "Button" field.

    In my script I use this:
    Code (csharp):
    1.  
    2. if (SimpleInput.GetButtonDown("RightControl"))
    3.  
    But nothing happens.
     
  29. Ill-Fish

    Ill-Fish

    Joined:
    Aug 23, 2015
    Posts:
    22
    Sorry I posted wrong code, but can't edit it currently.

    my code is:
    Code (csharp):
    1.  
    2. if (SimpleInput.GetKey(KeyCode.RightControl))
    3.  
     
  30. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Button Input X components are used for SimpleInput.GetButton functions. For SimpleInput.GetKey functions, you should use Key Input X components.
     
  31. Hulapyk

    Hulapyk

    Joined:
    Oct 13, 2020
    Posts:
    1
    Hi, my buddy and I messed around with this for a bit. But we were wondering if it's possible to adjust the speed on mobile movement (it's too fast for our game) and is it possible to either reduce the "drifting" effect, or completely turn it off, so our characters doesn't slide around when turning etc :)

    Thanks in advance!
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Are you talking about the example scene or SimpleInput.GetAxis function?
     
  33. skiftaaa

    skiftaaa

    Joined:
    Mar 31, 2020
    Posts:
    1
    How can we convert Input.mousePosition? to Simpleinput ??? Used to move the camera with my mouse, now from the joystick it sint possible?! replacing keyboard inputs worked for me, but how can i solve/replace the mousepositions ?
    thank you regards
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can call SimpleInput.GetAxis("Mouse X") and set your joystick's X axis to "Mouse X", as well. Then similar setup for "Mouse Y" axis.
     
  35. LaurieAnnis

    LaurieAnnis

    Joined:
    Jan 24, 2010
    Posts:
    63
    This asset is unbelievably useful, thank you! Everything works great right out of the box, super easy to set up. Happily donated via itch.io. For some reason, even though I had no trouble updating the Input to SimpleInput throughout my camera and player controllers, and it's working to control my player movement and camera via a joystick, the mouse still moves the camera just a bit when it's outside of the joystick. I don't think this has to do with SimpleInput at all, more likely my custom camera script, but I am stumped and thought I should ask. Does anyone have an idea where I should look for the potential cause of this? If I set the cursor to Locked it just disappears, but still works the same (works when you can manage to hover over the joystick, but also drifts when the mouse is not on top of it). Same thing if I set locked to None or Confined.
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I've previously said that we can use "Mouse X" axis for joystick but it looks like dragging the finger over the screen also changes value of "Mouse X" (internal Unity behaviour), so it was a bad suggestion of mine. Instead, you can use another axis with joystick (e.g. "Camera X") and then use that axis in your code. To give value to "Camera X" via mouse, as well, add an AxisInputMouse component with "Camera X" axis to an object in your scene.

    BTW, thank you for your support!
     
    LaurieAnnis likes this.
  37. LaurieAnnis

    LaurieAnnis

    Joined:
    Jan 24, 2010
    Posts:
    63
    Thank you so much for the reply! I fixed it without altering my code, but you put me on the right path. I just switch Type to Joystick Axis in the Mouse X and Mouse Y Input Manager fields (mouse control of the joystick still works this way):

    upload_2021-4-5_15-43-42.png
     
    yasirkula likes this.
  38. msabharwal

    msabharwal

    Joined:
    Apr 5, 2017
    Posts:
    4
    Sir, an excellent asset. I have been struggling to figure out how does the joystick know to connect to player or player 2, I can see there is horizontal and horizontal1 on the inspector and switching this does the work.

    What is the reference to this for player selection, I mean how is Horizontal1 related to the player and Horizontal to the other player.

    Sorry for asking a noob question, I am really not quite clear because I want to do more with the controls but am stuck at this.

    thanks for your time and help.

    Mohit

     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Each player's ExamplePlayerController component stores that player's control axes. So, the player with Horizontal1 axis takes input from the joystick with Horizontal1 axis.
     
  40. msabharwal

    msabharwal

    Joined:
    Apr 5, 2017
    Posts:
    4
    Thanks for clarifying, can you pls advise which part on the Joysticks code refer to the control axis is associated with Horizontal1, I can’t see any direct reference to the player from the Joystick or steering wheel scripts.

    thanks

    d
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    There are no direct references. Joystick have assignable axes in the Inspector. When you use these axes in SimpleInput.GetAxis, it just works.
     
  42. Rawr_RAAAAAAA

    Rawr_RAAAAAAA

    Joined:
    Sep 18, 2020
    Posts:
    1
    Can I convert SimpleInput.AxisInput to a float and how.
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can get
    axisInput.value
    but usually, you would go with
    SimpleInput.GetAxis("AxisName")
    .
     
  44. path123456

    path123456

    Joined:
    Mar 20, 2021
    Posts:
    8
    Hi, I am using the standard assets first-person controller I managed to get everything working except the run button how to that
    and thanks for the free asset pack :)
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd recommend you to search all occurrences of
    Input.
    in the code and replace them with
    SimpleInput.
    . Then, you can create a UI button for the jump action and add a "Button Input UI" component to it (if jump action uses SimpleInput.GetKeyDown, then you should attach a "Key Input UI" component to the UI button instead).
     
  46. path123456

    path123456

    Joined:
    Mar 20, 2021
    Posts:
    8
    thanks
     
    yasirkula likes this.
  47. demyter40

    demyter40

    Joined:
    Jul 1, 2021
    Posts:
    10
    Hello! I'm new. I want to make it so that when the buttons are pressed, the character does not move back and forth, but left and right. Could you drop the script for this
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I couldn't visualize your scenario in my mind. Can you post some screenshots describing your issue?
     
  49. demyter40

    demyter40

    Joined:
    Jul 1, 2021
    Posts:
    10
    upload_2021-7-2_11-13-40.png
    Here is a cube. It always moves forward, I need to make it so that when I press the buttons, it turns left and right!
    But your buttons move it back and forth, or just twist it. What do I need to do to make it move left and right?
    I'm new to this, could you explain in more detail or throw off the finished script?
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Make sure that Left button's Axis Input UI component has its Key set to Horizontal and Value set to -1. Right button's Axis Input UI component has its Key set to Horizontal and Value set to +1. Then it should work correctly, assuming that you can play the game using keyboard arrows without any issues.