To start - I'm very new at this. I watched a tutorial series to get a feel for Unity; it wasn't PSM-focused, now I need help. I'm trying to make a local multiplayer game where Player01 controls an object on the left side of the screen with the left joystick and Player02 controls an object on the right with the right stick. Here is the code I started to try to adapt for the Vita but I'm stuck: Code (JavaScript): #pragma strict //In here was KeyCode, but I want joystick input var moveUp : ; var moveDown : ; var speed : float = 10; function Update (Player01) { if (Input.GetAxis ("LeftV")) { rigidbody2D.velocity.y = speed; } else if (Input.GetAxis ("LeftV")) { rigidbody2D.velocity.y = speed *-1; } else { rigidbody2D.velocity.y = 0; } } function Update (Player02) { if (Input.GetAxis ("RightV")) { rigidbody2D.velocity.y = speed; } else if (Input.GetAxis ("RightV")) { rigidbody2D.velocity.y = speed *-1; } else { rigidbody2D.velocity.y = 0; } }
Whereabouts are you stuck? If this worked for keyboard input, but not for PSM maybe you need to setup your inputs (LeftV and RightV)? as per this guide https://psm.playstation.net/static/general/all/unity_for_psm/en/Documentation/Manual/PSMInput.html Although the code you've posted doesn't look like it would work at all at first glance...
For clarity these are the inputs you need to be reading Input.GetAxis("Left Stick Horizontal")); Input.GetAxis("Left Stick Vertical")); Input.GetAxis("Right Stick Horizontal")); Input.GetAxis("Right Stick Vertical"));
OK, I've made some adjustments and some progress. The game will get the input, but both players will move if either stick is pressed. Also, I can't figure out how to get them to move down, they will only move up(negative). Updated code: Code (JavaScript): #pragma strict var speed : float = 10; function Update () { if (Input.GetAxis("left stick vertical axis")) { rigidbody2D.velocity.y = speed; } else if (Input.GetAxis("left stick vertical axis")) { rigidbody2D.velocity.y = speed *-1; } else if (Input.GetAxis("right stick vertical axis")) { rigidbody2D.velocity.y = speed; } else if (Input.GetAxis("right stick vertical axis")) { rigidbody2D.velocity.y = speed *-1; } else { rigidbody2D.velocity.y = 0; } } Also: Where can I find the demo? I looked in all the installation folders but no luck.
From the documentation https://psm.playstation.net/static/...cumentation/Manual/PSMAdditionalPackages.html
you're using the GetAxis function wrong. Have a read of the documentation for inputs: http://docs.unity3d.com/ScriptReference/Input.GetAxis.html GetAxis returns -1...1, so you should use that directly on velocity.y. You're code currently says Code (JavaScript): if ( LeftStickMoved ) rigidbody y = speed else if ( LeftStickMoved ) rigidbody y = -speed so the 2nd if never hits as the first one will. you want something more like Code (JavaScript): rigidbody2D.velocity.y = speed * Input.GetAxis("left stick vertical axis"); As for moving both players... you only ever reference "rigidbody". Is this script attached to both players? (in which case you're running the same "move on stick change" code on both, and need a different script referring to different inputs for each players) Or is rigidbody the name of one of the objects?
Thank you everyone. Got it working. I made a separate script for each player and changed the usage of getaxis. I'm sure I'll be back with more questions