diff --git a/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs b/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs new file mode 100644 index 0000000000000000000000000000000000000000..2fc12d53817fa24996b9470cbaea88e19a7454f4 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GamepadInput : MonoBehaviour { + + [SerializeField] + float Deadzone; + float maxComparable; + + [SerializeField] + PlayerBehavior myPlayer; + + // Use this for initialization + void Start () { + maxComparable = 1 - Deadzone; + } + + // Update is called once per frame + void Update () { + float leftX = Input.GetAxis("Left Horizontal"); + float leftY = Input.GetAxis("Left Vertical"); + + /* Ratio of joystick amount over the deadzone */ + myPlayer.MoveHorizontal(leftX); + myPlayer.MoveVertical(leftY); + + if (Input.GetButton("Xbox B")) + myPlayer.Brake(); + } +} diff --git a/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs.meta b/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..f05fd74d948c84f93849019984281fe53fdb6129 --- /dev/null +++ b/CMPT306_Fall2017/Assets/Scripts/GamepadInput.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9ae2cb071c24c534ca4556fd157e062a +timeCreated: 1506465138 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CMPT306_Fall2017/Assets/Scripts/InputManagerScript.cs b/CMPT306_Fall2017/Assets/Scripts/InputManagerScript.cs index ee6fecd25c259fe03f8647da996249b95ed242f1..8c9a7b7bc3cddd23e8b7c26bf7e4e5e45786a380 100755 --- a/CMPT306_Fall2017/Assets/Scripts/InputManagerScript.cs +++ b/CMPT306_Fall2017/Assets/Scripts/InputManagerScript.cs @@ -17,10 +17,10 @@ public class InputManagerScript : MonoBehaviour { playerOneBehavior = playerOne.GetComponent<PlayerBehavior>(); playerTwoBehavior = playerTwo.GetComponent<PlayerBehavior>(); } - - // Update is called once per frame - void Update () { + + private void KeyboardInput() + { /** * Player One Movement Controls */ @@ -71,4 +71,21 @@ public class InputManagerScript : MonoBehaviour { playerTwoBehavior.Brake(); } } + + public void JoypadOneInput() + { + playerOneBehavior.MoveHorizontal(Input.GetAxis("Left Horizontal")); + playerOneBehavior.MoveVertical(Input.GetAxis("Left Vertical")); + + if (Input.GetButton("Xbox B")) + playerOneBehavior.Brake(); + + } + + // Update is called once per frame + void Update () { + KeyboardInput(); + + JoypadOneInput(); + } } diff --git a/CMPT306_Fall2017/Assets/Scripts/PlayerBehavior.cs b/CMPT306_Fall2017/Assets/Scripts/PlayerBehavior.cs index b24a2a032053924b9740475baa5fde1a444a3b81..a321d31e01d1e5ca6fcb2652512ed9efc1d193d1 100755 --- a/CMPT306_Fall2017/Assets/Scripts/PlayerBehavior.cs +++ b/CMPT306_Fall2017/Assets/Scripts/PlayerBehavior.cs @@ -40,22 +40,31 @@ public class PlayerBehavior : MonoBehaviour { { frameMovement.x -= acceleration; } - public void MoveRight() { frameMovement.x += acceleration; } - public void MoveUp() { frameMovement.y += acceleration; } - public void MoveDown() { frameMovement.y -= acceleration; } + public void MoveHorizontal(float f) + { + if(Mathf.Abs(f) <= 1) + frameMovement.x += f; + } + public void MoveVertical(float f) + { + if (Mathf.Abs(f) <= 1) + frameMovement.y += f; + } + + /** * Scale the player's velocity down, if brakeFraction is < zero */ diff --git a/CMPT306_Fall2017/ProjectSettings/InputManager.asset b/CMPT306_Fall2017/ProjectSettings/InputManager.asset index 17c8f538e2152c0a0310b4870979eeecece2153c..46a74d3263e02de35d5046d8f8156e421368cdb9 100644 --- a/CMPT306_Fall2017/ProjectSettings/InputManager.asset +++ b/CMPT306_Fall2017/ProjectSettings/InputManager.asset @@ -6,7 +6,7 @@ InputManager: serializedVersion: 2 m_Axes: - serializedVersion: 3 - m_Name: Horizontal + m_Name: Left Horizontal descriptiveName: descriptiveNegativeName: negativeButton: left @@ -14,15 +14,15 @@ InputManager: altNegativeButton: a altPositiveButton: d gravity: 3 - dead: 0.001 + dead: 0.3 sensitivity: 3 snap: 1 invert: 0 - type: 0 + type: 2 axis: 0 - joyNum: 0 + joyNum: 1 - serializedVersion: 3 - m_Name: Vertical + m_Name: Left Vertical descriptiveName: descriptiveNegativeName: negativeButton: down @@ -30,266 +30,26 @@ InputManager: altNegativeButton: s altPositiveButton: w gravity: 3 - dead: 0.001 + dead: 0.3 sensitivity: 3 snap: 1 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire1 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left ctrl - altNegativeButton: - altPositiveButton: mouse 0 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire2 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left alt - altNegativeButton: - altPositiveButton: mouse 1 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire3 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: left shift - altNegativeButton: - altPositiveButton: mouse 2 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Jump - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: space - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse X - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse Y - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 1 - joyNum: 0 - - serializedVersion: 3 - m_Name: Mouse ScrollWheel - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0 - sensitivity: 0.1 - snap: 0 - invert: 0 - type: 1 - axis: 2 - joyNum: 0 - - serializedVersion: 3 - m_Name: Horizontal - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0.19 - sensitivity: 1 - snap: 0 - invert: 0 - type: 2 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Vertical - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: - altNegativeButton: - altPositiveButton: - gravity: 0 - dead: 0.19 - sensitivity: 1 - snap: 0 invert: 1 type: 2 axis: 1 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire1 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 0 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire2 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 1 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Fire3 - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 2 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 + joyNum: 1 - serializedVersion: 3 - m_Name: Jump + m_Name: Xbox B descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: joystick button 3 + positiveButton: joystick 1 button 1 altNegativeButton: altPositiveButton: gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Submit - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: return - altNegativeButton: - altPositiveButton: joystick button 0 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Submit - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: enter - altNegativeButton: - altPositiveButton: space - gravity: 1000 - dead: 0.001 - sensitivity: 1000 - snap: 0 - invert: 0 - type: 0 - axis: 0 - joyNum: 0 - - serializedVersion: 3 - m_Name: Cancel - descriptiveName: - descriptiveNegativeName: - negativeButton: - positiveButton: escape - altNegativeButton: - altPositiveButton: joystick button 1 - gravity: 1000 - dead: 0.001 + dead: 0 sensitivity: 1000 - snap: 0 + snap: 1 invert: 0 type: 0 axis: 0 - joyNum: 0 + joyNum: 1