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.

PPJoy and Unity

Discussion in 'Editor & General Support' started by sclark39, Apr 24, 2009.

  1. sclark39

    sclark39

    Joined:
    Apr 24, 2009
    Posts:
    2
    I'm trying to get some alternative input devices working with Unity, but Unity doesn't seem to want to cooperate. It can receive mouse input, and it can get input from other gamepads, just not from the PPJoy virtual one.

    Any ideas why this might be, and how I could get it working?

    Tbanks.

    More Info:
    In the Input Manager it doesn't matter what Joy Num I choose, it always gets the input from the working gamepad.
    Before joystick input / mouse input only worked the first time I ran the game through the editor, after that it was like the game couldn't get focus. Today I'm not encountering this problem.
    I can see that the joystick I'm trying to use does work via the control panel.
    I'm using the Unity Trial in Windows. v.2.5.0f5
     
  2. sclark39

    sclark39

    Joined:
    Apr 24, 2009
    Posts:
    2
    Does anyone have any idea? Any thoughts? Anything?
     
  3. johnnycrich

    johnnycrich

    Joined:
    Sep 26, 2009
    Posts:
    6
    I hate to dig up and old topic, but I am also now having the same issue.

    Can anybody advise on this, pretty please?
     
  4. Simon_Prog

    Simon_Prog

    Joined:
    Dec 3, 2009
    Posts:
    4
    Hello, I'm currently having the same problem. Did anybody find a solution?

    That's really strange because all my games can use the PPJoy virtual joystick, but Unity doesn't seem to recognize it.

    Is there any solution (other virtual joystick softwares?) or is it impossible to use the PPJoy virtual joystick with unity?
     
  5. Raptor Claw

    Raptor Claw

    Joined:
    Jan 24, 2010
    Posts:
    11
    I too have the same problem using PPJoy with Unity. I'm running unity 2.61 on windows xp. I'm able to connect other joysticks (like the xbox 360 one) just fine.

    Has anybody done any research that could lead us in a possible direction. It seems so strange that unity wouldn't be able to recognize a virtual joystick. I looked all over for this problem and this is the only place I could find that it comes up.

    Do you think it could be possible to find a C# library that can grab the virtual joystick information and pass it on to Unity?

    Lets try and figure this out team I'm pulling my hair out over here.
     
  6. livemixlove

    livemixlove

    Joined:
    Sep 16, 2009
    Posts:
    17
    Yep, I'll just repeat that I too am having this problem.... hmmm. It's really weird. It's making me realize that glovepie works differently than I imagined.
     
  7. livemixlove

    livemixlove

    Joined:
    Sep 16, 2009
    Posts:
    17
    I imagine that you could get glovepie to send something through osc and then have c# take in that data through a port.
     
  8. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    513
    I too am having the very same problem... Unity seems to be unable to grab a PPJoy device...

    Mapping the output through GlovePIE then sending it through OSC seems to be a huge hassle... I'm already capturing video input usinf freetrack, so that would mean a 3rd app running just to get input into Unity..

    This really should be addressed... PPJoy is a very versatile tool and unity would be that much better if it supported virtual devices.

    Cheers
     
  9. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    513
    Well, I've done just what livemixlove said and set up glovePie to grab input from the TrackIR and send OSC messages to Unity with the values...

    This approach works well, despite the added hassle... But, there are some quirks one needs to work around...

    Apparently, GlovePIE has trouble sending OSC messages... meaning it doesn't properly format the data it's sending... so any floating point or negative values are poorly converted and result in bad values (they don't match the desired output)...

    So this renders sending any floats or negative values impossible with GlovePIE...

    So what I've done to correct this problem was this (a major kludge, IMO, but it got the job done)

    first, since glovePIE doesn't support floats, we have to work with integers. But to preserve the accuracy of the values (which range mostly from -0.5 to 0.5), we have first to multiply them by, say 10000, then round the result... this will shift the floating point up 5 decimal places, so then we can round them and remove the float altogether...

    ok, that's takes care of the floaters, so now for the negative values...

    Since we also cannot send negative values through OSC using GlovePIE, we have to add an offset to compensate... adding +5000 to the rounded value will shift it to half the positive range, so now the values will range from 0 to 10000 (and not from -5000 to 5000).

    Ok, now we can send this through OSC and not get bad results... but these values as they are won't do much good in Unity (we were dealing with values from -.5 to .5), so now we have to undo these operations in Unity to get workable values again...

    So what I've done was to first remove the offset (subtract 5000), then divide the result by 10000 again, so the value can return to it's original state...

    It's necessary to make sure you're using floats in unity though... the values as they come in from the OSC message are integers, so first we must pass them on to a float, then divide by 10000, otherwise the result will most likely be a big round zero.

    Anyways... this approach, however complicated, does work in the end... I used a trackIR but it should work with a PPjoy device too...

    Hope it helps

    Cheers
     
  10. Raptor Claw

    Raptor Claw

    Joined:
    Jan 24, 2010
    Posts:
    11
    I found a similar workaround to the problem. I’m using a programming language called processing (http://processing.org/) to grab the virtual joystick data and then pass it to unity using UDP. I do find it odd that we need to go through such great lengths to do something so simple but at least it works.

    Here is the code I used:

    Processing Code

    Code (csharp):
    1.  
    2. /**
    3. * you will need to download an install the following libaries
    4. * in order to run this code:
    5. * UDP: [url]http://ubaa.net/shared/processing/udp/[/url]
    6. * procontroll: [url]http://creativecomputing.cc/p5libs/procontroll/[/url]
    7. *
    8. * @author Andy Saia
    9. */
    10.  
    11. // import UDP library
    12. import hypermedia.net.*;
    13. //import procontroll library
    14. import procontroll.*;
    15. import java.io.*;
    16.  
    17. // define the UDP object "udp" must be the name of the project
    18. UDP udp;
    19.  
    20. String message  = str( key );   // the message to send
    21. String ip       = "localhost";  // the remote IP address
    22. int port        = 6100;     // the destination port
    23.  
    24. // define controllers
    25. ControllIO controll;
    26. ControllDevice device;
    27. //make control Sticks for pitch and roll
    28. ControllStick yawPitch;
    29. ControllStick rollStick;
    30.  
    31. void setup() {
    32.  
    33.   // create a new datagram connection on port 6000
    34.   // and wait for incomming message
    35.   udp = new UDP( this, 6000 );
    36.   udp.log( false );         // <-- printout the connection activity
    37.  
    38.   controll = ControllIO.getInstance(this);
    39.   device = controll.getDevice("PPJoy Virtual joystick 1");
    40.   device.printSticks();
    41.   yawPitch = device.getStick(0);
    42.   rollStick = device.getStick(1);
    43. }
    44.  
    45. void draw()
    46. {
    47.   String pitch = Float.toString(map(yawPitch.getY(), -1, 1, -180, 180));
    48.   String roll = Float.toString(map(rollStick.getY(), -1, 1, 90, -90));
    49.  
    50.   message = (roll + ", " + pitch);
    51.   print(message + "\n");
    52.    
    53.   //send joystick data every frame
    54.   udp.send(message, ip, port );
    55. }
    56.  

    C# Unity3d Code


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. using System;
    5. using System.Text;
    6. using System.Net;
    7. using System.Net.Sockets;
    8. using System.Threading;
    9.  
    10. public class UDPReceive : MonoBehaviour {
    11.    
    12.     // receiving Thread
    13.     Thread receiveThread;
    14.  
    15.     // udpclient object
    16.     UdpClient client;
    17.  
    18.     // public
    19.     // public string IP = "127.0.0.1"; default local
    20.     public int port; // define > init
    21.     public bool DebugMode = false;
    22.  
    23.     // infos
    24.     public string lastReceivedUDPPacket="";
    25.     public string allReceivedUDPPackets=""; // clean up this from time to time!
    26.  
    27.     public float cameraYaw = 0.0f;
    28.     public float cameraPitch = 0.0f;
    29.     public float cameraRoll = 0.0f;
    30.    
    31.    
    32.    // start from shell
    33.     private static void Main()
    34.     {
    35.        UDPReceive receiveObj=new UDPReceive();
    36.        receiveObj.init();
    37.  
    38.       string text="";
    39.       do
    40.       {
    41.           text = Console.ReadLine();
    42.       }
    43.       while(!text.Equals("exit"));
    44.     }
    45.     // start from unity3d
    46.     public void Start()
    47.     {
    48.        
    49.        init();  
    50.     }
    51.    
    52.    
    53.     // OnGUI
    54.     void OnGUI()
    55.    {
    56.        if (DebugMode)
    57.        {
    58.            Rect rectObj = new Rect(40, 10, 200, 400);
    59.            GUIStyle style = new GUIStyle();
    60.            style.alignment = TextAnchor.UpperLeft;
    61.            GUI.Box(rectObj, "# UDPReceive\n127.0.0.1 " + port + " #\n"
    62.                     + "shell> nc -u 127.0.0.1 : " + port + " \n"
    63.                     + "\nLast Packet: \n" + lastReceivedUDPPacket
    64.                     + "\n\nAll Messages: \n" + allReceivedUDPPackets
    65.                  , style);
    66.        }
    67.    }
    68.      
    69.     // init
    70.     private void init()
    71.     {
    72.         if (DebugMode)
    73.         {
    74.             print("UDPSend.init()");
    75.  
    76.             // define port
    77.             //port = 6100;
    78.  
    79.             // status
    80.             print("Sending to 127.0.0.1 : " + port);
    81.             print("Test-Sending to this Port: nc -u 127.0.0.1  " + port + "");
    82.         }
    83.  
    84.         receiveThread = new Thread(
    85.             new ThreadStart(ReceiveData));
    86.         receiveThread.IsBackground = true;
    87.         receiveThread.Start();
    88.  
    89.     }
    90.  
    91.    // receive thread
    92.     private  void ReceiveData()
    93.     {
    94.  
    95.         client = new UdpClient(port);
    96.         while (true)
    97.         {
    98.  
    99.             try
    100.             {
    101.                 IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
    102.                 byte[] data = client.Receive(ref anyIP);
    103.  
    104.                 string text = Encoding.UTF8.GetString(data);
    105.  
    106.                 if (DebugMode)
    107.                 {
    108.                     print(">> " + text);
    109.                 }
    110.                
    111.                 lastReceivedUDPPacket=text;
    112.  
    113.                 stringParser(text);
    114.                
    115.                 // ....
    116.                 allReceivedUDPPackets=allReceivedUDPPackets+text;
    117.                
    118.             }
    119.             catch (Exception err)
    120.             {
    121.                 print(err.ToString());
    122.             }
    123.         }
    124.     }
    125.  
    126.     private void stringParser(string data)
    127.     {
    128.         String[] stringArray;
    129.         //parsing data into string array
    130.         stringArray = data.Split(',');
    131.         //converting from string to float adding to roll and pitch varibles
    132.         cameraRoll = System.Convert.ToSingle(stringArray[0]);
    133.         cameraPitch = System.Convert.ToSingle(stringArray[1]);
    134.     }
    135.  
    136.     // getLatestUDPPacket
    137.     // cleans up the rest
    138.     public string getLatestUDPPacket()
    139.     {
    140.        allReceivedUDPPackets="";
    141.        return lastReceivedUDPPacket;
    142.     }
    143.    
    144.     void OnDisable()
    145.     {
    146.         if ( receiveThread!= null)
    147.         receiveThread.Abort();
    148.  
    149.         client.Close();
    150.     }
    151. }
    152.  

    I’m planning on making a full tutorial on this project when I’m done with it. I’ll post a link when all the bugs are worked out.
     
    abdulthegamer likes this.
  11. SomeGuy

    SomeGuy

    Joined:
    Feb 27, 2009
    Posts:
    1
    Any chance you'd be willing to post or share an example of how you got this to work? I seem to have glovePie working for grabbing the TrackIR values, but the UDP stuff is giving me fits.

    Anything you could offer would be much appreciated...
     
  12. Raptor Claw

    Raptor Claw

    Joined:
    Jan 24, 2010
    Posts:
    11
    I've been trying a bunch of different experiments and it seems that HarvesteR's solution is the best. Sending OSC directly out of gloviePie eliminates the use of another program like processing. Also I've been sending floats and negative numbers out of gloviePie just fine by converting them to strings and then back to floats as soon as they get into unity.

    I put together a bare bones example that simple passes mouse position from gloviePie to Unity. You should be able to easily modify it. Let me know if you have any trouble getting it to work.
     

    Attached Files:

  13. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    73
    Just to bump the topic...

    I'm having the same problem -- Unity does no recognize virtual joysticks, and it's the only application I've encountered that doesn't.

    Many thanks to those who figured out a work-around, but it would be great to see this issue address in the next release.
     
  14. web76

    web76

    Joined:
    Nov 4, 2009
    Posts:
    142
    Also bump, still a problem with virtual joysticks, need 3d connexion input..

    Web76
     
unityunity