Search Unity

Unity 5 - New Mobile Assets - Joystick problem

Discussion in 'Android' started by Wrakor, Mar 5, 2015.

  1. Wrakor

    Wrakor

    Joined:
    Mar 5, 2015
    Posts:
    1
    Hey, I was trying the new Mobile Assets now called "CrossPlatformInput" and I can't get the joystick prefab (MobileSingleStickControl) to work properly.

    The moment I touch the joystick, it moves to the lower left corner of the screen and I can only drag it up and right (these two directions work).

    I also tried the MobileAircraftControls prefab and this one worked properly, so the problem might be with the single joystick prefab. Anyone else having the same situation?
     
    hopetolive and babakrostami76 like this.
  2. adrianolsk

    adrianolsk

    Joined:
    Jul 11, 2013
    Posts:
    4
    I got the exact same problem here, didn´t find a solution yet.
     
  3. Good-Friar

    Good-Friar

    Joined:
    Mar 7, 2015
    Posts:
    6
    Hey Guys, I spotted this
    that seem to address the problem you describe. Hope it helps. I have the problem where I build to my tablet, everything looks fine but none of the movement controls function. Ver 4.6 still do but not Ver 5???
     
    hopetolive, MrEsquire and adrianolsk like this.
  4. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Oh thank god its not just me! I posted a question about it on the Unity Answers forum, but no one has come back with an answer yet.

    For a few hours I thought I was going crazy, thinking it was something stupid I forgot to do.

    Hope we get an answer soon as I can't continue on with my game till a solution is found :(
     
  5. adrianolsk

    adrianolsk

    Joined:
    Jul 11, 2013
    Posts:
    4
    I found a solution, I think it´s a bug.

    Here is what I did:

    In the MobileJoyStick inside the MobileSingleStickControl, I change the pivot to "bottom, left" and in the
    Joystick.cs I changed the line in OnEnable method


    from:

    m_StartPos = transform.position;

    to:

    m_StartPos = new Vector3 (transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);


    I also changed the x and y position of the MobileJoyStick to 150 to fit on the screen.

    I hope it work for you, let me know.
     
    waleedmm and szefff like this.
  6. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Hey, I might have a sloppy fix for this.

    I noticed that in OnPointerUp(), the transform.position of the actual joystick was changing to 0, 0, 0 every time thanks to m_startPos.

    So a work around, which is still kinda sloppy but here it goes...

    First, take a look at the image below...



    While in Play mode, hover your mouse cursor over the button. The red circle and underline shows that the position value will change when you're hovering over the button. Take a note of the values.

    Next, go back to OnPointerUp()

    and do something like this...

    Code (CSharp):
    1.         public void OnPointerUp(PointerEventData data)
    2.         {
    3.  
    4.             transform.position = new Vector3(190, 130, 0);
    5.  
    6.             UpdateVirtualAxes(m_StartPos);
    7.  
    8.  
    9.         }
    The values 190, 130, 0 were my own values that I got from that window while in play mode. Using this, it goes back to its start point and NOT the bottom left corner.

    Hope this helps :)

    UPDATE: You know, I suspect it has something to do with the Movement Range variable...because has anyone else noticed that when you drag it to the left, it goes way too far off screen? but when you drag it to the right, it barely moves at all? Hmmm
     
    Last edited: Mar 8, 2015
  7. adrianolsk

    adrianolsk

    Joined:
    Jul 11, 2013
    Posts:
    4
    Yes it´s basicly the same thing I did,
    but I stored the initial position as a new Vector3,

    One thing that I noticed when I comented every piece of code and left only this:

    Code (CSharp):
    1. void OnEnable()
    2. {
    3.          m_StartPos = transform.position;          
    4. }
    5.  
    6. public void OnPointerUp(PointerEventData data)
    7. {
    8.             transform.position = m_StartPos;
    9.        
    10. }
    it move to the bottom left after I release the mouse button.

    but when I change the code to store the transform.position and transform.localPosition, and use this values later on OnPointerUp the location was correct.
    Something is changing the localPosition.
    So when you create a new Vector3 with the position that you wanted you are discarding the localPosition that was afecting the position.

    But I had to fix the pivot of the joystick to put it to work on the right place on the screen.
     
    Farrukh01 likes this.
  8. Derek-Wong

    Derek-Wong

    Joined:
    Jan 5, 2015
    Posts:
    16
    Hi All,
    I found that this should be some changes made on the OnDrag pointerEventData. In order to fix this I have changed the way to move the joystick by changing all transform.position >>> this.getComponent<RectTransform>().anchordedPosition. The idea is to move the joystick in the canvas directly.
     
    FotusCN likes this.
  9. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Hey my friends,

    Good news! Someone found a simple solution to the problem via my question about it in the Unity Answer Forums.

    User Wizza said:

    Fixed it like a charm for me :)

    If you want to give him credit, this is the original post: http://answers.unity3d.com/question...napping-to-bottom-left-cor.html#answer-919202
     
  10. Good-Friar

    Good-Friar

    Joined:
    Mar 7, 2015
    Posts:
    6
    Hey, I know I'm only new here but in my last post I added a You Tube clip that addressed exactly that problem and gave exactly that answer. Just sayin'!
     
  11. adrianolsk

    adrianolsk

    Joined:
    Jul 11, 2013
    Posts:
    4
    Yes the video addressed the same problem and how to solve it, also tweak it a bit. I didn´t see that part that day.
    Sorry and thanks.
     
    Good-Friar likes this.
  12. bart_bender

    bart_bender

    Joined:
    Mar 21, 2015
    Posts:
    20
    Hi, i had the same problem
    This code runs for me

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4.  
    5. namespace UnityStandardAssets.CrossPlatformInput
    6. {
    7.     public class Joystick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
    8.     {
    9.         public enum AxisOption
    10.         {
    11.             // Options for which axes to use
    12.             Both, // Use both
    13.             OnlyHorizontal, // Only horizontal
    14.             OnlyVertical // Only vertical
    15.         }
    16.  
    17.         public int MovementRange = 100;
    18.         public AxisOption axesToUse = AxisOption.Both; // The options for the axes that the still will use
    19.         public string horizontalAxisName = "Horizontal"; // The name given to the horizontal axis for the cross platform input
    20.         public string verticalAxisName = "Vertical"; // The name given to the vertical axis for the cross platform input
    21.  
    22.         Vector3 m_StartPos;
    23.         bool m_UseX; // Toggle for using the x axis
    24.         bool m_UseY; // Toggle for using the Y axis
    25.         CrossPlatformInputManager.VirtualAxis m_HorizontalVirtualAxis; // Reference to the joystick in the cross platform input
    26.         CrossPlatformInputManager.VirtualAxis m_VerticalVirtualAxis; // Reference to the joystick in the cross platform input
    27.  
    28.         void Start() //OnEnable()
    29.         {
    30.             //m_StartPos = transform.position;
    31.             m_StartPos = this.GetComponent<RectTransform>().anchoredPosition3D;
    32.             CreateVirtualAxes();
    33.         }
    34.  
    35.         void UpdateVirtualAxes(Vector3 value)
    36.         {
    37.             var delta = m_StartPos - value;
    38.             delta.y = -delta.y;
    39.             delta /= MovementRange;
    40.             if (m_UseX)
    41.             {
    42.                 m_HorizontalVirtualAxis.Update(-delta.x);
    43.             }
    44.  
    45.             if (m_UseY)
    46.             {
    47.                 m_VerticalVirtualAxis.Update(delta.y);
    48.             }
    49.         }
    50.  
    51.         void CreateVirtualAxes()
    52.         {
    53.             // set axes to use
    54.             m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
    55.             m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
    56.  
    57.             // create new axes based on axes to use
    58.             if (m_UseX)
    59.             {
    60.                 m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
    61.                 CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
    62.             }
    63.             if (m_UseY)
    64.             {
    65.                 m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
    66.                 CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
    67.             }
    68.         }
    69.  
    70.  
    71.         public void OnDrag(PointerEventData data)
    72.         {
    73.          
    74.  
    75.             Vector3 newPos = Vector3.zero;
    76.  
    77.             if (m_UseX)
    78.             {
    79.                 int delta = (int)(data.position.x - m_StartPos.x);
    80.                 delta = Mathf.Clamp(delta, -MovementRange, MovementRange);
    81.                 newPos.x = delta;
    82.             }
    83.  
    84.             if (m_UseY)
    85.             {
    86.                 int delta = (int)(data.position.y - m_StartPos.y);
    87.                 delta = Mathf.Clamp(delta, -MovementRange, MovementRange);
    88.                 newPos.y = delta;
    89.             }
    90.             this.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(m_StartPos.x + newPos.x, m_StartPos.y + newPos.y, m_StartPos.z + newPos.z);
    91.             UpdateVirtualAxes(this.GetComponent<RectTransform>().anchoredPosition3D);
    92.         }
    93.  
    94.  
    95.         public void OnPointerUp(PointerEventData data)
    96.         {
    97.             this.GetComponent<RectTransform>().anchoredPosition3D = m_StartPos;
    98.             UpdateVirtualAxes(m_StartPos);
    99.         }
    100.  
    101.  
    102.         public void OnPointerDown(PointerEventData data) { }
    103.  
    104.         void OnDisable()
    105.         {
    106.             // remove the joysticks from the cross platform input
    107.             if (m_UseX)
    108.             {
    109.                 m_HorizontalVirtualAxis.Remove();
    110.             }
    111.             if (m_UseY)
    112.             {
    113.                 m_VerticalVirtualAxis.Remove();
    114.             }
    115.         }
    116.     }
    117. }
     
  13. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    So this still not officially fixed after Unity broke it, another annoying glitch, btw broke in Unity 4.6.3 also..UI team whatsup?
     
  14. AndresMendez

    AndresMendez

    Joined:
    Apr 18, 2015
    Posts:
    1
    Hi, I hope this can help:

    In the void start of the Joystick Script: add the vector 3 values to the m_StartPos(as you can see below). When you click or touch the button in the game the axis will change to the vector3 of 150,150,0.

    You can see what the m_StartPos is below.


    void Start()
    {
    m_StartPos = new Vector3 (150, 150, 0);//transform.position;
    CreateVirtualAxes();
    }
     
  15. IOZO

    IOZO

    Joined:
    Jun 26, 2010
    Posts:
    55
    I have a different issue I think. It' not an issue with the joystick position. That seems to be ok but I can't move the joystick on built version of the game (Android/Nexus7)

    I tried all your suggestions but nothing works in my case.

    In Unity5 I can move the joystick in the game window with the mouse and it also works with Unity remote on my nexus 7.

    When building the game the joystick reacts very badly. It moves but I can't drag it anywhere, it always comes back to its original position immediately after touching it and trying to move it. I use the modified version of joystick.cs as shown in Devis tutorial.
     
  16. tinyminds

    tinyminds

    Joined:
    Aug 6, 2015
    Posts:
    1
    This is driving me mad, can not get any joystick controls working on android same as the post above. could it be to do with my player settings? cos it works with unity remote. is it a bug or am i just doing something really stupid?
     
  17. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Any fix for this yet - is issue still present on latest builds?
     
  18. edricknight

    edricknight

    Joined:
    Sep 5, 2015
    Posts:
    1
    Thank you worked!
     
  19. knickerbocker

    knickerbocker

    Joined:
    May 8, 2014
    Posts:
    29
    This is a huge pain in the ass. Doesn't work.
     
  20. CrandellWS

    CrandellWS

    Joined:
    Oct 31, 2015
    Posts:
    154
    That was what I was looking for example the Survival Shooter Joystick script has :
    Code (csharp):
    1.  
    2.     void OnEnable() {
    3.  
    4.         startPos = transform.position;
    5.         CreateVirtualAxes();
    6.     }
    7.  
    and the standard assets has

    Code (csharp):
    1.  
    2.         void OnEnable()
    3.         {
    4.             CreateVirtualAxes();
    5.         }
    6.  
    7.         void Start()
    8.         {
    9.             m_StartPos = transform.position;
    10.         }
    11.  
    So I used:

    Code (csharp):
    1.  
    2.     void OnEnable() {
    3.         CreateVirtualAxes();
    4.     }
    5.  
    6.     void Start() {
    7.         startPos = transform.position;
    8.     }
    9.  
    Thanks for the help with using virtual joysticks for mobile input
     
    elloumimohamed and SparkleDan like this.
  21. SparkleDan

    SparkleDan

    Joined:
    Nov 25, 2015
    Posts:
    1
    This did the job, thanks.
     
  22. Deleted User

    Deleted User

    Guest

    For the record, the issue here is that during OnEnable, transform.position is (0,0,0).

    For whatever reason, this value is calculated later. It does work in Start, but because I was concerned that it was important that it fire in OnEnable, this is a workaround you can do.

    Create your own Coroutine called something, like Init and call it from inside of OnEnable

    Have Init wait until the end of frame, and then ask for transform.position. It will now be the value the script is expecting, and not (0,0,0).
     
  23. Farrukh01

    Farrukh01

    Joined:
    Aug 17, 2016
    Posts:
    1
    Ok i confirm that this is a bug and my unity 5.02f1 still has it fix for it is.
    Code (csharp):
    1.  
    2.         void OnEnable()
    3.         {
    4.             CreateVirtualAxes();
    5.             m_StartPos = transform.localPosition;
    6.  
    7.         }
    8.  
    every thing will work fine if you change position to localPosition , no need to change in OnPointerUp().

    On unity remote android and on windows this is working fine.
    But when i build apk and run on android mobile its not working.


    Thanks.
     
    Last edited: Aug 17, 2016
  24. artosking

    artosking

    Joined:
    Jun 15, 2014
    Posts:
    5
    Hi all.
    I'm having same issue on 5.4.3p1. Even i've made everything like in video (or any of your propossition) the joystick don't work correctly. It still changes its position when i touch it.

    Any ideas?
     
  25. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    217
    I found the problem, I think. Change the pivot point of your joystick to (rect transform) .5,.5 for center of the image. If not, the center calculation is the corner of your image.
     
  26. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    Hi all,

    I'm using the CrossPlatformInput Joystick in Unity 5.4.2. They have fixed the problem with OneEnable/Start.

    However, I have still found 3 problems (some of which have already been pointed out and fixed by others):
    1. The pivot of the joystick is assumed to be in the center (0.5, 0.5). If you use a different pivot, the joystick will be way off once you start dragging.
    2. It is assumed that you are dragging with your finger (or the mouse pointer) at the pivot point. To me it would be more intuitive if I am dragging the joystick around at the point where I first touch it. For example, if I grab a piece of paper by the top corner, I wouldn't expect the center of the paper to suddenly move its center to where I am grabbing it, once I start moving, but that is exactly what happens with this joystick.
    3. The MovementRange is used as being in device units, but if you use a canvas scaler, it should really be given in scaled units because those are what you set on your joystick and other UI elements.
    1+2 can be fixed by simply remembering the position where the drag started, and take every drag position relative to that.
    3 can be fixed by scaling the movement range according to the canvas scaler.

    I have made the following changes to the code to fix this:

    Code (CSharp):
    1.        // Added member variables
    2.         Vector3 m_PointerDownPos; // FIXED: Exact position of pointerdown so drag can be relative to that and not to pivot
    3.         Vector3 m_MovementRange; // FIXED:Movement range in device units as scaled by canvas scaler
    4.  
    5.         // Original OnEnable method - CreateVirtualAxes must be called in here
    6.         void OnEnable()
    7.         {
    8.             CreateVirtualAxes();
    9.         }
    10.  
    11.         // Changed Start method
    12.         void Start()
    13.         {
    14.             m_StartPos = transform.position;
    15.  
    16.             // FIXED: Calculate movement range in device units as scaled by canvas scaler
    17.             CanvasScaler canvasScaler = GetComponentInParent<CanvasScaler> ();
    18.             if (canvasScaler != null) {
    19.                 m_MovementRange = canvasScaler.transform.localScale * MovementRange;
    20.             }
    21.             else {
    22.                 m_MovementRange = Vector3.one * MovementRange;
    23.             }
    24.         }
    25.  
    26.         // Changed UpdateVirtualAxes method
    27.         void UpdateVirtualAxes(Vector3 value)
    28.         {
    29.             var delta = m_StartPos - value;
    30.             delta.y = -delta.y;
    31.             if (m_UseX)
    32.             {
    33.                 delta.x /= m_MovementRange.x; // FIXED: Use movement range in device units as scaled by canvas scaler
    34.                 m_HorizontalVirtualAxis.Update(-delta.x);
    35.             }
    36.  
    37.             if (m_UseY)
    38.             {
    39.                 delta.y /= m_MovementRange.y; // FIXED: Use movement range in device units as scaled by canvas scaler
    40.                 m_VerticalVirtualAxis.Update(delta.y);
    41.             }
    42.         }
    43.  
    44.         // Changed OnDrag method
    45.         public void OnDrag(PointerEventData data)
    46.         {
    47.             // FIXED: Made this method faster by using 2 floats for delta X and Y instead of a vector3 which is later discarded
    48.             float deltaX = 0;
    49.             float deltaY = 0;
    50.  
    51.             if (m_UseX)
    52.             {
    53.                 deltaX = Mathf.Clamp (data.position.x - m_PointerDownPos.x, -m_MovementRange.x, m_MovementRange.x); // FIXED: Take drag position relative to pointerdown position instead of pivot; Use movement range in device units as scaled by canvas scaler
    54.             }
    55.  
    56.             if (m_UseY)
    57.             {
    58.                 deltaY = Mathf.Clamp (data.position.y - m_PointerDownPos.y, -m_MovementRange.y, m_MovementRange.y); // FIXED: Take drag position relative to pointerdown position instead of pivot; Use movement range in device units as scaled by canvas scaler
    59.             }
    60.             transform.position = new Vector3(m_StartPos.x + deltaX, m_StartPos.y + deltaY, m_StartPos.z);
    61.             UpdateVirtualAxes(transform.position);
    62.         }
    63.  
    64.         // Changed OnPointerDown method
    65.         public void OnPointerDown(PointerEventData data) {
    66.             m_PointerDownPos = data.position; // CYLFIX: Remember the exact position of pointerdown so drag can be relative to that and not to pivot
    67.         }
     
    Last edited: Apr 22, 2017
  27. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    38
    hey guys!

    I try everything you mentioned on this topic, but i still have the issue.

    How can i fix that?
     
  28. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    Can you be a bit more specific about what changes you made and what problems you are still experiencing?

    If you made the changes suggested in my post (the one prior to yours), are you sure that your changes are actually active. Set a breakpoint to make sure the changed code is being executed. (My apologies if this is all basic stuff and you know what you're doing, but it's hard to tell from your post.)
     
  29. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    38
    well i tried the method to change enable() with start() and i still got the issue (the joystick change his position when i touch it).
     
  30. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    If you are using a recent version of Unity (I'm on 5.4.2), that problem should be fixed already, i.e. they already moved m_StartPos = transform.position to the Start method. But that doesn't solve the problem completely, as I wrote in my first post, I still found 3 problems. The most likely is perhaps that the pivot is assumed to be at the center, so if it isn't, the joystick changes position very noticeably when you start dragging. Please read my post again. If you still have the problem, you are welcome to message me directly.
     
  31. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    38
    I use Unity 5.4.1. After i read your post, i follow the 3 steps.

    For all of them i still have the problem.

    Is it possible to use the coordinates of the UI element, and put it into a vector3 for m_StartPos?
     
  32. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    I started a conversation with you to help you troubleshoot. It will be unhelpful to do that in a public forum.
     
  33. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    OK, after looking at kaisersam's code I found out it didn't work because I missed 2 items in my original post:

    1. I did not make it clear that the OnEnable method should include the CreateVirtualAxes call. It did in the version I was using but maybe not in all of them.
    2. I forgot to include my changed OnPointerDown method.

    I have edited my original post to include these 2 changes.
     
  34. sinamin

    sinamin

    Joined:
    Jun 28, 2017
    Posts:
    3
    How are you using Canvas Scaler? I'm new to this and I don't see that being used in the original code.

    I'm basically just trying to get your #1 and #2 fix to work in my project. I already have the joystick working, but I don't like the behavior which you described and attempted to fix. When I implement the code you posted, my joystick becomes unresponsive. I'm wandering if this is because I implemented everything without the canvas scaler parts.
     
  35. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    The Canvas Scaler is a script on the Canvas. It's what you use to make your UI work with different resolutions. Refer to https://docs.unity3d.com/Manual/HOWTO-UIMultiResolution.html for more. But it won't make the joystick unresponsive.

    If the joystick is unresponsive it is probably because one of the methods that set things up is not being called. For example, CreateVirtualAxes() has to be called in OnEnable or Start. If you still can't get it to work, show me the whole file please.
     
  36. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Don't worry, bruh, you're only 3 years late.
    And yes, when we release the joystick (OnPointerUp) we generally want it to return to it's [0,0] state.
     
  37. nXFiles

    nXFiles

    Joined:
    Jun 21, 2017
    Posts:
    1
    Hello Everyone

    I am having the save issue here but I am not using the cross platform asset, I just use this code and it is really killing me. it worked on previous versions of unity but after I updated to 2017, I cant move the ball up and down, it just drops down on left side of the screen and just moves left and right with accelero-meter and I cant find any solution. it really kills me, is there any help that I can get ?

    my code
    1. public class RollMe : MonoBehaviour {

    2. public float ballSpeed;
    3. private Rigidbody ballRigidBody;

    4. void Main()
    5. {
    6. Screen.sleepTimeout = SleepTimeout.NeverSleep;
    7. }
    8. // Use this for initialization
    9. void Start () {
    10. ballRigidBody = GetComponent<Rigidbody>();
    11. }
    12. // Update is called once per frame
    13. void Update () {
    14. if(SystemInfo.deviceType==DeviceType.Desktop)
    15. {
    16. float moveHorizontal = Input.GetAxis("Horizontal");
    17. float moveVertical = Input.GetAxis("Vertical");
    18. Vector3 movementControl = new Vector3(moveHorizontal, 0, moveVertical);
    19. ballRigidBody.AddForce(movementControl * ballSpeed * Time.deltaTime);
    20. }
    21. else
    22. {
    23. Vector3 movementControl = new Vector3(Input.acceleration.x, 0, Input.acceleration.z);
    24. ballRigidBody.AddForce(movementControl * ballSpeed * Time.deltaTime);
    25. }
    26. }
    27. }
    thanks in advance
     
  38. Tatilon

    Tatilon

    Joined:
    May 13, 2018
    Posts:
    1
    A forma mais simples de resolver o problema do Joystick indo pro canto esquerdo ao ser clicado, é essa:

    1 - Apague o OnEnable
    2 - Coloque o método CreativeVirtualAxes() dentro do void Start()

    // Ex.

    void Start()
    {
    m_StartPos = transform.position;
    CreativeVitualAxes();

    }

    pronto! bem simples e bem fácil.
     
  39. ToThinkIsToCreate

    ToThinkIsToCreate

    Joined:
    Jun 15, 2017
    Posts:
    16
    Is there a way to modify the Joystick code from standard assets to only control z and x axis'. I have tried altering a number of different parts but don't fully understand what all needs to change. I can roll my marble left and right but not back and forward.
     

    Attached Files:

  40. rickjohnston61

    rickjohnston61

    Joined:
    Feb 12, 2019
    Posts:
    12
    I have tired to use several mobile device packages from unity asset store...none of the work except dual controller in standard assets download which is at best cheesy! The Joystick package was promising but the object gets skewed depending on device screen and no matter what the button control moves in the opposite direction of my touch movement???
    I'm going to create my own albeit I really shouldn't have to do this...
     
  41. clindholst

    clindholst

    Joined:
    Nov 18, 2016
    Posts:
    7
    Hi Rick, I haven't tried using the stock packages for a while because my own stuff just works, so I may be wrong, but when you say it "gets skewed depending on device screen", sounds like the problem still is with the CanvasScaler. I solved that problem. Try to read through my posts in this thread and see whether it helps.
     
  42. rickjohnston61

    rickjohnston61

    Joined:
    Feb 12, 2019
    Posts:
    12
    Thank you for reply. Yes I have the canvas scale set to 'size with screen' the issue is the joystick object only. If I use standard asset "button" controls they are scaled just fine. The other thing is that there are several other objects on the canvas (text and other buttons) and they all scale correctly.
    I'll continue to investigate on my own or just go the route of using standard dual controls but the issue with them is I have an onMouseButtonDown(1) that is getting invoked when I use both my fingers to move and rotate the camera on a touch screen. I saw a video of placing a panel all over where controls are to prevent touch from getting through so I'll see how that goes later today.
    Thanks again!
    Cheers!
    Rick...
     
unityunity