Search Unity

Unity PS Vita Input Not Working

Discussion in 'PSM' started by thommoboy, Aug 19, 2014.

  1. thommoboy

    thommoboy

    Joined:
    Jul 20, 2012
    Posts:
    59
    Hey,

    i have this code currently for my mouselook of a first person camera:

    Code (JavaScript):
    1. @script AddComponentMenu ("Camera-Control/Mouse Look")
    2.  
    3. //PS Vita
    4. var PSVita : boolean = false;
    5. var Stick : String;
    6.  
    7. enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2}
    8. var axes = RotationAxes.MouseXAndY;
    9. var normalMinimumY : float = -90;
    10. var normalMaximumY : float = 85;
    11. var proneMinimumY : float = -20;
    12. var proneMaximumY : float = 40;
    13. var offsetX : float = 0;
    14. var offsetY : float = 0;
    15. var kickTime : float = 0;
    16. var mineCamera : Camera;
    17. var menu : MainMenu;
    18. var controllerScript : CODcontroller;
    19.  
    20. private var sensitivity : float;
    21. private var savedSensitivity : float = 2.0;
    22. private var minimumX : float = -360;
    23. private var maximumX : float = 360;
    24. private var minimumY : float;
    25. private var maximumY : float;
    26. private var rotationX : float = 0;
    27. private var rotationY : float = 0;
    28. private var originalRotation : Quaternion;
    29.  
    30. function Start()
    31. {
    32.     if (rigidbody) rigidbody.freezeRotation = true;
    33.     originalRotation = transform.localRotation;
    34.     Screen.lockCursor = true;
    35. }
    36.  
    37. function Update ()
    38. {
    39.     if(!Screen.lockCursor)
    40.     {
    41.         //savedSensitivity = menu.sensitivity; //Update sensitivity only when cursor isn't locked
    42.         return;
    43.     }
    44.     /*
    45.     if(controllerScript.state == 0 || controllerScript.state == 1)
    46.     {
    47.         sensitivity = savedSensitivity * Time.timeScale;  //you can add " * Time.timeScale" if you want affect sensitivity in slow motion
    48.         minimumY = normalMinimumY;
    49.         maximumY = normalMaximumY;
    50.     }
    51.     else if(controllerScript.state == 2)
    52.     {
    53.         sensitivity = savedSensitivity/2 * Time.timeScale; //you can add " * Time.timeScale" if you want affect sensitivity in slow motion
    54.         minimumY = proneMinimumY;
    55.         maximumY = proneMaximumY;
    56.     }
    57.     */
    58.    
    59.     if (axes == RotationAxes.MouseXAndY)
    60.     {
    61.         rotationX += Input.GetAxis("Mouse X") * sensitivity /30 * (mineCamera.fieldOfView + offsetX);
    62.         rotationY += Input.GetAxis("Mouse Y") * sensitivity /30 * (mineCamera.fieldOfView + offsetY);
    63.  
    64.         rotationX = ClampAngle (rotationX, minimumX, maximumX);
    65.         rotationY = ClampAngle (rotationY, minimumY, maximumY);
    66.        
    67.         var xQuaternion : Quaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
    68.         var yQuaternion : Quaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
    69.        
    70.         transform.localRotation = originalRotation * xQuaternion * yQuaternion;
    71.     }
    72.    
    73.     if(axes == RotationAxes.MouseX)
    74.     {      
    75.         if(PSVita)
    76.             transform.Rotate(0, Input.GetAxis(Stick + "StickH") * sensitivity /30 * mineCamera.fieldOfView + offsetX, 0);
    77.         else
    78.             transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivity /30 * mineCamera.fieldOfView + offsetX, 0);
    79.     }
    80.    
    81.     if(axes == RotationAxes.MouseY)
    82.     {
    83.         if(PSVita)
    84.             rotationY += Input.GetAxis(Stick + "StickV") * sensitivity / 60 * mineCamera.fieldOfView + offsetY;
    85.         else
    86.             rotationY += Input.GetAxis("Mouse Y") * sensitivity /60 * mineCamera.fieldOfView + offsetY;
    87.            
    88.         rotationY = ClampAngle (rotationY, minimumY, maximumY);
    89.         yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
    90.         transform.localRotation = originalRotation * yQuaternion;
    91.         /*
    92.         if(rotationY > proneMaximumY && controllerScript.state == 2)
    93.         {
    94.             transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler (-35, 0, 0),Time.deltaTime*5);
    95.             rotationY = 360 - transform.rotation.eulerAngles.x;
    96.         }
    97.         else if (rotationY < proneMinimumY && controllerScript.state == 2)
    98.         {
    99.             transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler (15, 0, 0),Time.deltaTime*4);
    100.             rotationY = -transform.rotation.eulerAngles.x;
    101.         }
    102.         */
    103.     }
    104.     //KickBack from weaponscript
    105.     if(kickTime < 0)
    106.     {
    107.         //reset offset
    108.         offsetY = Mathf.SmoothDamp(offsetY, 0.0, offsetY, Time.deltaTime);
    109.         offsetX = Mathf.SmoothDamp(offsetX, 0.0, offsetX, Time.deltaTime);
    110.     }
    111.     else
    112.     {
    113.         kickTime -= Time.deltaTime;
    114.     }
    115. }
    116.  
    117. static function ClampAngle (angle : float, min : float, max : float) : float
    118. {
    119.     if(angle < -360.0)
    120.         angle += 360.0;
    121.     if(angle > 360.0)
    122.         angle -= 360.0;
    123.     return Mathf.Clamp (angle, min, max);
    124. }
    i am following this example i was given on this forum a while back:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Joystick : MonoBehaviour {
    5.  
    6.     public string Stick;
    7.  
    8.     void Update ()
    9.     {
    10.         const float smooth = 5.0F;
    11.         const float tiltAngle = -90.0F;
    12.  
    13.         // See InputManager (Edit > Project > Input) for mapping from <string> to <axis>
    14.         float x = Input.GetAxis(Stick + "StickH") * tiltAngle;
    15.         float y = Input.GetAxis(Stick + "StickV") * tiltAngle;
    16.  
    17.         Quaternion target = Quaternion.Euler(y, x, 0);
    18.         transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
    19.     }
    20. }
    however the players camera is not turning
     
  2. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    var axes = RotationAxes.MouseXAndY;

    ....

    if(axes == RotationAxes.MouseX)
    {
    if(PSVita)
    transform.Rotate(0, Input.GetAxis(Stick + "StickH") * sensitivity /30 * mineCamera.fieldOfView + offsetX, 0);
    else
    transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivity /30 * mineCamera.fieldOfView + offsetX, 0);
    }

    -----

    See the problem there? Your "axes" variable will never work for that condition where you have the PSVita code, for one.
     
  3. thommoboy

    thommoboy

    Joined:
    Jul 20, 2012
    Posts:
    59
    that problem has been fixed however in the build of the game i still cannot look around using the right stick
     
  4. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    did you study the input examples that comes with the editor installation?