Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity 5 CrossPlatformInput

Discussion in 'Editor & General Support' started by whirlpoole, Feb 25, 2015.

  1. whirlpoole

    whirlpoole

    Joined:
    Feb 25, 2015
    Posts:
    1
    On Unity 5, I am trying to get the DualTouchControls prefab to work but with no luck. I have added it to a scene with the standard FPS controller but it does not work. The touchpads appear and the jump button appears, but they do not react when pressed. Has anyone managed to get them working? If so, can you walk me through the process of setting it up?

    Thanks!
     
    Last edited: Feb 25, 2015
    ccoltharp and winf_randy like this.
  2. winf_randy

    winf_randy

    Joined:
    Aug 27, 2014
    Posts:
    3
    Also looking for an explanation of this prefab and the crossplatforminput asset in general.
     
  3. Altered

    Altered

    Joined:
    Mar 4, 2015
    Posts:
    12
    Hoping someone can help out on t his, I've been trying to figure this out for a few days, without much success!
     
  4. darnoldi

    darnoldi

    Joined:
    Jan 21, 2015
    Posts:
    23
    Also trying to do this.
     
  5. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,136
    Yeah tell me about it! - Posted about this also. Even if I build the ExampleProject (which is the slowest to buitld!) the 2d platformer controls do not work on my nexus properly - I tap the direction stick and it jumps to the bottom-left corner
     
  6. darnoldi

    darnoldi

    Joined:
    Jan 21, 2015
    Posts:
    23
    At least you are getting some response to the controls. I get Nothing at all.
     
  7. archimi_swiss

    archimi_swiss

    Joined:
    Oct 13, 2014
    Posts:
    4
    ccoltharp likes this.
  8. darnoldi

    darnoldi

    Joined:
    Jan 21, 2015
    Posts:
    23
    Ok so if like me you are getting no response at all, just add a UI/EventSystem component to your scene.

    Im a bit embarrassed about this one 8).
     
    ccoltharp likes this.
  9. Altered

    Altered

    Joined:
    Mar 4, 2015
    Posts:
    12
    That does indeed make the prefabs work! Thanks for the heads up!!!
     
  10. Devin-Curry

    Devin-Curry

    Joined:
    Sep 30, 2013
    Posts:
    22
    In case anyone was still looking for more documentation on CrossPlatformInput, I've made a video about it here:


    it's using the CrossPlatformInput that was in 4.6 but the scripts and prefabs are pretty much the same. Also, I'm planning on doing more videos on CrossPlatformInput in the future using Unity 5. Hope this helps someone :)
     
    winf_randy and darnoldi like this.
  11. Altered

    Altered

    Joined:
    Mar 4, 2015
    Posts:
    12
    Thanks Devin! Your Touch scripts are on point! If anyone is struggling with mobile input, check out Devin's videos! Also, make sure you switch to a mobile build platform in settings (like iOS or Android) or your mobile controls won't show up no matter what :)
     
  12. darnoldi

    darnoldi

    Joined:
    Jan 21, 2015
    Posts:
    23
    Thanks Devin. Good job!
     
  13. ccoltharp

    ccoltharp

    Joined:
    Apr 1, 2015
    Posts:
    5

    Hey Devin- thanks for the great tutorials. Unfortunately, the new Unity 5 "standard" assets are not like their 4.6 brethren. I'd love it if you did something similar to this, but starting from a fresh install of Unity 5 and using relevant imports to make the same thing. First of all, there is no dual joystick CPI prefab like there was in 4.6; only a dual touch and single stick control. And even after switching the build to iOS, enabling mobile input, and adding the UI event system, I can't seem to get either of those to react to my frequent screen jabbing on my Unity remote. Have you tried it in 5 yet?
     
    Big-Ed and winf_randy like this.
  14. Ibzy

    Ibzy

    Joined:
    Sep 15, 2013
    Posts:
    112
    I also followed Devin's video (very helpful!) but am having issues with the touch controls with Unity 5.

    The buttons appear to work fine in the editor (mouse click being treated as a touch) but as soon as I build and install on a device, there is very little response. The joystick sticks in position very often causing the player character to move "automatically" in the direction the stick froze at, and to test my theory I added some buttons with no functionality other than to change colour on touch (standard setting for a button). These dont always change colour when tapped as one would expect.

    Seems like the new version doesn't fully detect touches?
     
  15. dman35226

    dman35226

    Joined:
    Jul 14, 2015
    Posts:
    2
    Yea like videos from Devin hope he makes one updating script for that video on unity 5.0 & maybe a video on the dual one.

    - Dementwe
     
  16. dman35226

    dman35226

    Joined:
    Jul 14, 2015
    Posts:
    2
    Hey devin you stream?

    - Dementwe
     
  17. Devin-Curry

    Devin-Curry

    Joined:
    Sep 30, 2013
    Posts:
    22
    Once things at work slow down and I get more free time I'll be looking into doing this with that latest version of Unity and recording a video of it. Sorry, Dementwe, I don't stream. Just the recorded Youtube videos at the moment
     
  18. WiktorCal

    WiktorCal

    Joined:
    Mar 1, 2014
    Posts:
    4
    I'm having the same kind of problem right now... And I think I have found where it went wrong:
    In the Joystick.cs of the CrossPlatformInput asset, m_StartPos is the reference point of the joystick. The rest of the codes use the m_StartPos and the OnDrag event to calculate the displacement of the joystick.

    However, probably because when upgrading their new UI system, the Unity team forgot about this asset and leave the initiation of m_StartPos to be m_StartPos = transform.position which is now meaningless in UI objects.

    Code (CSharp):
    1.  
    2. void OnEnable()
    3. {
    4. m_StartPos = transform.position;
    5. m_StartPos = GetComponent<RectTransform>().anchoredPosition;
    6. CreateVirtualAxes();
    7. }
    8.  
    9. void UpdateVirtualAxes(Vector3 value)
    10. {
    11. var delta = m_StartPos - value;
    12. delta.y = -delta.y;
    13. delta /= MovementRange;
    14. if (m_UseX)
    15. {
    16. m_HorizontalVirtualAxis.Update(-delta.x);
    17. }
    18.  
    19. if (m_UseY)
    20. {
    21. m_VerticalVirtualAxis.Update(delta.y);
    22. }
    23. }
    24.  
    So, it's obvious that once we fix that line of code, every thing will be just fine.

    I'm very exited to find that though unity team did not set the Transform's .position in RectTransform (RectTransform derives from Transform), they did really set the .localPosition. Actually, we can access the UI element's RectTransform as Transform here, so transform.localPosition will be perfect.

    .......................

    And it seems that the .localPosition of the RectTransform is just the same as the .anchoredPosition which is "The position of the pivot of this RectTransform relative to the anchor reference point."
    So you will have to set the anchor of the joystick UI element to the Bottem Left corner...

    Code (CSharp):
    1.  
    2. void OnEnable()
    3. {
    4. m_StartPos = transform.localPosition;
    5. CreateVirtualAxes();
    6. }
    7.  
    I'm frustrated by this asset... Though you can use it now, you have to keep the anchor there or write more code to calculate the UI element's absolute position on the canvas by yourself...

    Looking forward to other options...

    Hope this can help guys trying to use this asset...
     
    Last edited: Aug 2, 2015
  19. Devin-Curry

    Devin-Curry

    Joined:
    Sep 30, 2013
    Posts:
    22
    Hi all, this is long over-due but I finally got around to revisiting the touch joysticks using the Unity 5 Standard Assets

    I've also uploaded a .unitypackage of everything in this video to my website: http://www.devination.com/2015/09/unity-touch-joysticks-tutorial-touch.html


    @Kailang good find here, I didn't think to try that. I solved it by changing OnEnable() to Start()
     
    LilGames likes this.
  20. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Can anyone advise how to access in scripts.

    I am trying to re-purpose the jump button to throw an object i am carrying. Trying touch.Began and .End without success. What i would like to do is call the jump button in update and then do touch began and touch.End on that with time variable which would give me a float to put in my throw method.
     
  21. jktarban

    jktarban

    Joined:
    Feb 12, 2014
    Posts:
    3
    I'm doing a 2d top view spaceship game where the left joystick controls the ship movement and the right joystick controls the fire direction. I've followed the the two joystick tutorial above. The problem is sometimes when I hold and moved the two UI's (ship movement and fire direction), the UI position resets to its center position (the clamp) and stopped moving and firing. I have no idea what's going on.
     
  22. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Hey,
    I'm using the touchpad control, not the joystick. I can't get getAxis out of it. Anybody have the same issue?
     
  23. fromium

    fromium

    Joined:
    Jun 7, 2013
    Posts:
    7
    Great find! I'm trying to use the cross platform inputs to use the joysticks, but how do I add a reference to the required name space in JavaScript?

    the required: "Using Crossplatforminput" does not work in JS.
     
    Last edited: Dec 19, 2016
  24. Jeswer

    Jeswer

    Joined:
    Aug 18, 2015
    Posts:
    5
    Was very confused by all the children in dual touch being inactive and not being able to activate them.
    Then I read the readme provided with Crossplatforminput and figured it out.
     
  25. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Hey i have an issue with the dual touch pad.

    Actually, it works with the look touch area, but when i use the move touch area, my fps character doesn't move.

    I try to change absolute with swipe, but with the swipe, it's very chaotique.

    Is there a fix for this?
     
  26. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    527
    I got Devin's code working well in a project where I had pixels per unit set to the default 100, but my game is set to PPU of 8 (and camera size 12.5). The joystick no longer moves correctly. I reduced Movement Range to 2 or 3 and still, the joystick will go in a circle limitation, but it won't do in-between positions. (it's either the full limit of the circle, or back to center start position).

    Anyone have insight on what else needs modifying to get the stick moving anywhere between start position and the distance limit?