Search Unity

Virtual Joystick Component for Iphone/Ipad?

Discussion in 'iOS and tvOS' started by Sfernald, Dec 23, 2010.

  1. Sfernald

    Sfernald

    Joined:
    Apr 27, 2010
    Posts:
    20
    I was wondering if there is a "virtual joystick" component out there that I could use for iphone/ipad joystick play?

    Something that I could just plug in that would provide the graphics/scripting of the virtual joysticks, if that makes sense. Don't really want to spend the time to make virtual joysticks/button controls myself if possible.
     
  2. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,367
    Yes, they are pretty easy to use, you can found them in Standard Assets (Mobile) folder,
    The script is called Joystick. Here is how to use it:
    Create an empty object, add an GUITexture on it (add your stick texture to), add the Joystick component to the same GameObject.
    Then create an other component (on your character for example, to move it with the input you'll retrieve from the Joystick component) then:
    Use Joystick.position to retrieve position in screen space, relative to the center of the tap zone (defined in your Joystick public properties).
    For example:
    - if (Joystick.position.x > 0)//the joystick was moved to the right
    - if (Joystick.position.x < 0)//the joystick was moved to the left
    - if (Joystick.position.y > 0)//the joystick was moved up
    - if (Joystick.position.y < 0)//the joystick was moved down
    //those position always goes from 0 to 1 and 0 to -1, where 1(or -1) means that your stick wont move any further and of course 0 means that the stick is at the center of that axis.
    Sorry for my quick answer, if you don't understand well, I'll try to respond later on with a clearer answer, I'm a bit busy now.
    Cheers,
     
    Last edited: Dec 23, 2010
  3. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    @tatoforever :: Could you please giv some reference or sample game wich uses the same joystick control for the basic player movement.

    Thanks In advance
     
  4. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,367
    All Mobile example scenes/prefabs uses it.
     
  5. Draco18s

    Draco18s

    Joined:
    Aug 15, 2011
    Posts:
    110
    Bit of a necro here, but I am unable to locate the sample projects that are being referenced in this thread and am unable to figure out how to use the Joystick script that is a standard asset.

    Thanks
     
  6. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    Just slap it on a scene and read its position values
     
  7. Draco18s

    Draco18s

    Joined:
    Aug 15, 2011
    Posts:
    110
    Nice use of the word "it" :|

    Which "it" are you referring to?
    If you are referring to "the sample project" then you didn't finish reading my post, as I don't have one and am unable to read any values.
    If you are referring to "the Joystick script" then you are a moron, as you can't "slap that on a scene" and "read its values" because: 1) scripts can't be attached to scenes and 2) those important values are their default 0 values and worthless.

    That said, after posting my last message I located the PDF that was required to explain how to use the script. Since then, however, I've lost track of it.
     
  8. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    Its a prefab that you place on the scene... But since the spelling police attitude is here you can ask further questions from someone else
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah can't be arsed helping with that attitude.
     
  10. Draco18s

    Draco18s

    Joined:
    Aug 15, 2011
    Posts:
    110
    I don't HAVE a prefab. I have a JAVASCRIPT. I'm pretty sure I said that.
    Oh wait, I did:

    The reason I replied with sarcasm is because the unhelpful reply was unhelpful. I have managed to locate the PDF that the sample code came with (and thus have a working project now) but I am unable to further help others because I've lost track of where I found that PDF.
     
  11. altair2020

    altair2020

    Joined:
    Mar 6, 2011
    Posts:
    48
    Hi everyone,

    I need you to forget Draco18s frustrations and help me out here.

    I will not swear and i will try not be be woefully stupid.

    But i have the same situation.

    I have added a GUITexture to my project and dragged and dropped the Single Joystick Prefab to the GUITexture.

    Suddenly there is a thumb stick appearing and it looks promising.

    Which values do i adjust to make this thumb stick move in relation to my gameObject that is my player ?

    So what i mean to say

    Tatoforever says:

    Use Joystick.position to retrieve position in screen space, relative to the center of the tap zone (defined in your Joystick public properties).

    what Joystick public properties ? how to i access these from another script ?

    I am using C# so if the Joystick script in in Javascrip am i in deep water?
     
    Last edited: Dec 12, 2011
  12. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    Simple way to access it directly is to add this to your script:

    public Joystick jstick;

    then drag the joystick object from scene to that variable in inspector and then just access jstick.position or etc in your code :)

    there are others ways too like using find and so on

    edit: or (maybe) directly Joystick.joysticks[0].position
     
    Last edited: Dec 12, 2011
  13. nexxus

    nexxus

    Joined:
    Dec 19, 2011
    Posts:
    2
    Yep. This the way it SHOULD work, however it does NOT. This is what happens:

    Assets/Standard Assets/Character Controllers/Sources/Scripts/MouseLook1.cs(41,33): error CS0103: The name `Joystick' does not exist in the current context

    And I have no clue why. BUT if take a duplicate of the FirstPersonControl script located in the same package and copy/paste my code just after the Joystick variable declaration in that file, I can see the public vars in the inspector. I don't really think that's the way it should be done.

    Then using the Joystick script in C# file, like modified version of the MouseLook script, seems to be impossible what ever I try. I also tried the C# version of the Joystick script but I still get the same error.

    This doesn't work either I get the same error like the Joystick script didn't exist in my project. Does anyone have any clue why this happens?
     
  14. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
  15. VAN-D00M

    VAN-D00M

    Joined:
    Dec 24, 2013
    Posts:
    44

    I am trying to achieve the same thing here. What did you end up doing to make it work?