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

Can't get Unity to recognize PS4 axis inputs, PS4 button or touch pad

Discussion in 'Editor & General Support' started by Benjiman, Nov 17, 2013.

  1. Benjiman

    Benjiman

    Joined:
    Nov 16, 2013
    Posts:
    2
    Hi all,

    I layed out all the Keycodes for JoystickButton 0 - 19 in a simple switch case statement and found most of the buttons on the PS4 controller. But I'm having some trouble finding the following inputs:

    • Playstation button
    • Up / Down / Left / Right
    • Touch pad press down
    • Touch pad touch
    • Right directional stick press down
    • Directional pads direction inputs

    Here's a graphical representation with what I'm having trouble with:
    $ps4.jpg

    I'd also like to make sure I don't have inputs wrong in Unity, so here's a screenshot of the current setup of inputs:
    $unity input mgr.png

    Any suggestions would be appreciated :)
     
  2. Fingar

    Fingar

    Joined:
    Feb 21, 2013
    Posts:
    10
    Hello! Just got a DS4 myself!
    I've been mapping out pretty much the same as you, but I've gotten a little further.

    You seem to have mapped out the "Horizontal" and "Vertical" right. Are you sure you're testing them right?
    A simple debug-line should be enough to check if it works:


    void Update()
    {
    Debug.Log(Input.GetAxis("Horizontal"));
    }


    If that doesen't work.. something might be wrong with the windows xinput settings of the controller...

    Other than that:
    - The Y-axes for both thumbsticks should be inverted
    - Left thumbstick X Y should be unity-input's "X-axis" and "Y-axis" (Like you have done for "Horizontal" and "Vertical")
    - Right thumbstick X Y should be unity-input's "3rd-axis" and "6th-axis" (Strange, huh?)
    - The L2 R2 button are buttons like you have set up, but they are also based on axes. L2 is the "4th-axis" and R2 is the "5th-axis".
    - The D-Pad is also based on axes. Left Right is the "7th-axis". Up Down is the "8th-axis"
    - For the PS button, the "Positive" should be "joystick button 12"
    - For the Trackpad button, the "Positive" shoud be "joystick button 13"

    I haven't got the touchpad or the sixaxis to work yet, but I think that's xinputs fault and not unity. Maybe someone else has a solution for that?


    Good luck!
     
    carlosgutierrezTW and ccaunca like this.
  3. THERJ3D

    THERJ3D

    Joined:
    Oct 4, 2014
    Posts:
    9
    Found this while trying to lock down some of the controls.

     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    My new input system Rewired handles the PS4 pad without issues. You can assign any of the controls including the touchpad button. I've mapped it for Windows (native and Unity), OSX (native and Unity), Linux, and Android for consistency. Additionally, there's no need for an Xbox 360/XInput mapping driver for the PS4 pad.

    Here are the correct mappings for Windows:

    Left Stick X - Axis 0
    Left Stick Y - Axis 1 (inverted)
    Right Stick X - Axis 2
    Right Stick Y - Axis 5 (inverted)
    L2 - Axis 3 (but this axis zeros at -1 -- Rewired fixes this)
    R2 - Axis 4 (also zeros at -1)
    D-Pad Up - Axis 7 +
    D-Pad Right - Axis 6 +
    D-Pad Down - Axis 7 -
    D-Pad Left - Axis 6 -
    X - Button 1
    Circle - Button 2
    Square - Button 0
    Triangle - Button 3
    L1 - Button 4
    R1 - Button 5
    Share - Button 8
    Options - Button 9
    PS - Button 12
    Touchpad - Button 13
    Left Stick Button - Button 10
    Right Stick Button - Button 11

    However, realize the mappings can vary based on your platform. OSX has some differences as well as Linux and Android.

    Besides fixing the L2/R2 issue, Rewired also maps the D-Pads to buttons instead of axes. And Rewired eliminates the issue of your joystick ID changing from run to run or if the joystick is unplugged and re-plugged, along with tons of other features. Check it out in my sig.
     
    Last edited: Oct 4, 2014
    niquionoe and Lazulite like this.
  5. THERJ3D

    THERJ3D

    Joined:
    Oct 4, 2014
    Posts:
    9
    Thanks for the info guava man, I will check out your asset.
     
    guavaman likes this.
  6. jellybit

    jellybit

    Joined:
    Nov 21, 2009
    Posts:
    32
    This is great information, and answers most of my questions except for one. Everything I've read seems to treat the PS4 touchpad only as a button (which happens when you click it in), but does not give any information on using it as a touchpad. Does anyone know what that maps to, or how to find out what it maps to? Thanks!
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    The data is there (I've seen it doing some testing), but you cannot get it without directly pulling the data from the raw HID input report of the device. Sony chose to use non-standard Usages for the gyro and the trackpad, so they will not show up in any system that relies on standard Generic Desktop HID report structures (buttons, axes, etc.) You will also have to interpret this data yourself, essentially writing your own PS4 gamepad driver/SDK.
     
    Last edited: Nov 17, 2014
  8. jellybit

    jellybit

    Joined:
    Nov 21, 2009
    Posts:
    32
    Ah very helpful. Thank you. I guess I'll have to make different plans.
     
  9. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    260
    Has anyone written this driver? I would love to use PS4 touchpad input! Also, Rewired looks awesome! I use InControl currently, but I will definitely switch to Rewired in the future. Looks much better for multiplayer support.
     
    guavaman likes this.
  10. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    There is support for the PS4 touchpad and you can simulate the mouse with it, just search for DS4Input
     
  11. Maart003

    Maart003

    Joined:
    Jun 7, 2016
    Posts:
    2
    Hey guys, does this also work voor the motion control??? I need it for a school project.
     
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    To use the gyro, accelerometer, touchpad, vibration, and light control, you have to use a special driver like DS4 Windows.
     
  13. Riderfan

    Riderfan

    Joined:
    Jan 10, 2013
    Posts:
    514
    Hi there.

    I'm trying to access the PS4 touchpad button (index 13). When setting up an action id, is that mapped to Center3?

    Calling GetButtonDown(13) doesn't seem to be returning true so I'm trying to set up some mapping.

    thanks
     
  14. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    You're asking a question about Rewired, but this is not a Rewired thread. I received your email via the support form and answered it there.
     
  15. Deleted User

    Deleted User

    Guest

    This post is old, but for people looking for answers the old input manager is very ugly when you're not using a standard game controller and many other things. The new Input System is better.