diff --git a/Assets/Scripts/Game/Controllers/PlayerController.cs b/Assets/Scripts/Game/Controllers/PlayerController.cs index 195dad1..607bcb9 100644 --- a/Assets/Scripts/Game/Controllers/PlayerController.cs +++ b/Assets/Scripts/Game/Controllers/PlayerController.cs @@ -77,17 +77,23 @@ void InitRigidbody () { } void Update () { - HandleMovement (); - } + } + + void FixedUpdate() + { + HandleMovement(); + HandleCelestialBodies(); + + } - void HandleMovement () { + void HandleMovement () { HandleEditorInput (); if (Time.timeScale == 0) { return; } // Look input - yaw += Input.GetAxisRaw ("Mouse X") * inputSettings.mouseSensitivity / 10 * mouseSensitivityMultiplier; - pitch -= Input.GetAxisRaw ("Mouse Y") * inputSettings.mouseSensitivity / 10 * mouseSensitivityMultiplier; + yaw += Input.GetAxisRaw ("Look X") * inputSettings.mouseSensitivity / 10 * mouseSensitivityMultiplier; + pitch -= Input.GetAxisRaw ("Look Y") * inputSettings.mouseSensitivity / 10 * mouseSensitivityMultiplier; pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y); float mouseSmoothTime = Mathf.Lerp (0.01f, maxMouseSmoothTime, inputSettings.mouseSmoothing); smoothPitch = Mathf.SmoothDampAngle (smoothPitch, pitch, ref pitchSmoothV, mouseSmoothTime); @@ -101,13 +107,13 @@ void HandleMovement () { // Movement bool isGrounded = IsGrounded (); Vector3 input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")); - bool running = Input.GetKey (KeyCode.LeftShift); + bool running = Input.GetAxis("Throttle") < 0; targetVelocity = transform.TransformDirection (input.normalized) * ((running) ? runSpeed : walkSpeed); smoothVelocity = Vector3.SmoothDamp (smoothVelocity, targetVelocity, ref smoothVRef, (isGrounded) ? vSmoothTime : airSmoothTime); //bool inWater = referenceBody if (isGrounded) { - if (Input.GetKeyDown (KeyCode.Space)) { + if (Input.GetAxis("Throttle") > 0) { rb.AddForce (transform.up * jumpForce, ForceMode.VelocityChange); isGrounded = false; } else { @@ -116,12 +122,12 @@ void HandleMovement () { } } else { // Press (and hold) spacebar while above ground to engage jetpack - if (Input.GetKeyDown (KeyCode.Space)) { + if (Input.GetAxis("Throttle") > 0) { usingJetpack = true; } } - if (usingJetpack && Input.GetKey (KeyCode.Space) && jetpackFuelPercent > 0) { + if (usingJetpack && Input.GetAxis("Throttle") > 0 && jetpackFuelPercent > 0) { lastJetpackUseTime = Time.time; jetpackFuelPercent -= Time.deltaTime / jetpackDuration; rb.AddForce (transform.up * jetpackForce, ForceMode.Acceleration); @@ -164,8 +170,9 @@ bool IsGrounded () { return grounded; } - void FixedUpdate () { - CelestialBody[] bodies = NBodySimulation.Bodies; + void HandleCelestialBodies() + { + CelestialBody[] bodies = NBodySimulation.Bodies; Vector3 gravityOfNearestBody = Vector3.zero; float nearestSurfaceDst = float.MaxValue; @@ -227,4 +234,4 @@ public Rigidbody Rigidbody { } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Controllers/Ship.cs b/Assets/Scripts/Game/Controllers/Ship.cs index d202ad0..bd7bca3 100644 --- a/Assets/Scripts/Game/Controllers/Ship.cs +++ b/Assets/Scripts/Game/Controllers/Ship.cs @@ -60,16 +60,17 @@ void Update () { } void HandleMovement () { + Debug.Log(Input.GetAxis("Select")); // Thruster input - int thrustInputX = GetInputAxis (leftKey, rightKey); - int thrustInputY = GetInputAxis (descendKey, ascendKey); - int thrustInputZ = GetInputAxis (backwardKey, forwardKey); + float thrustInputX = Input.GetAxis("Horizontal"); + float thrustInputY = Input.GetAxis("Throttle"); + float thrustInputZ = Input.GetAxis("Vertical"); thrusterInput = new Vector3 (thrustInputX, thrustInputY, thrustInputZ); // Rotation input - float yawInput = Input.GetAxisRaw ("Mouse X") * rotSpeed * inputSettings.mouseSensitivity / 100f; - float pitchInput = Input.GetAxisRaw ("Mouse Y") * rotSpeed * inputSettings.mouseSensitivity / 100f; - float rollInput = GetInputAxis (rollCounterKey, rollClockwiseKey) * rollSpeed * Time.deltaTime; + float yawInput = Input.GetAxisRaw ("Look X") * rotSpeed * inputSettings.mouseSensitivity / 100f; + float pitchInput = Input.GetAxisRaw ("Look Y") * rotSpeed * inputSettings.mouseSensitivity / 100f; + float rollInput = Input.GetAxis("Roll") * rollSpeed * Time.deltaTime; // Calculate rotation if (numCollisionTouches == 0) { @@ -105,17 +106,6 @@ void TeleportToBody (CelestialBody body) { rb.MovePosition (body.transform.position + (transform.position - body.transform.position).normalized * body.radius * 2); } - int GetInputAxis (KeyCode negativeAxis, KeyCode positiveAxis) { - int axis = 0; - if (Input.GetKey (positiveAxis)) { - axis++; - } - if (Input.GetKey (negativeAxis)) { - axis--; - } - return axis; - } - void HandleCheats () { if (Universe.cheatsEnabled) { if (Input.GetKeyDown (KeyCode.Return) && IsPiloted && Time.timeScale != 0) { @@ -209,4 +199,4 @@ public Rigidbody Rigidbody { } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Interactions/Interactable.cs b/Assets/Scripts/Game/Interactions/Interactable.cs index 992c9e9..5d986f5 100644 --- a/Assets/Scripts/Game/Interactions/Interactable.cs +++ b/Assets/Scripts/Game/Interactions/Interactable.cs @@ -4,10 +4,12 @@ public class Interactable : MonoBehaviour { - public string interactMessage = "Press F to interact"; + public string interactMessage = "Press F (Y) to interact"; protected bool playerInInteractionZone; public UnityEngine.Events.UnityEvent interactEvent; + bool selecting = false; + protected virtual void Interact () { if (interactEvent != null) { interactEvent.Invoke (); @@ -15,10 +17,17 @@ protected virtual void Interact () { } protected virtual void Update () { - if (playerInInteractionZone && Input.GetKeyDown (KeyCode.F)) { + if (playerInInteractionZone && Input.GetAxis("Toggle") > 0) { + if (selecting) { + return; + } + selecting = true; GameUI.CancelInteractionDisplay (); Interact (); } + else { + selecting = false; + } } protected virtual void OnTriggerEnter (Collider c) { @@ -42,4 +51,4 @@ public void ForcePlayerInInteractionZone () { playerInInteractionZone = true; } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/ShipHUD.cs b/Assets/Scripts/Game/ShipHUD.cs index e0c36bc..bbca1d7 100644 --- a/Assets/Scripts/Game/ShipHUD.cs +++ b/Assets/Scripts/Game/ShipHUD.cs @@ -30,6 +30,7 @@ public class ShipHUD : MonoBehaviour { LockOnUI lockOnUI; Ship ship; CelestialBody aimedBody; + bool selecting = false; void Start () { // Need to draw UI AFTER floating origin updates, otherwise may flicker when origin changes @@ -65,14 +66,20 @@ void UpdateUI () { if (Time.timeScale != 0) { aimedBody = FindAimedBody (); - - if (Input.GetMouseButtonDown (0)) { + if (Input.GetAxis("Select") > 0 || Input.GetMouseButtonDown(0)) { + if (selecting) { + return; + } + selecting = true; if (lockedBody == aimedBody) { lockedBody = null; } else { lockedBody = aimedBody; } } + else { + selecting = false; + } } if (aimedBody && aimedBody != lockedBody) { @@ -275,4 +282,4 @@ public void SetActive (bool active) { head.gameObject.SetActive (active); } } -} \ No newline at end of file +} diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 17c8f53..7770db0 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -25,10 +25,10 @@ InputManager: m_Name: Vertical descriptiveName: descriptiveNegativeName: - negativeButton: down - positiveButton: up - altNegativeButton: s - altPositiveButton: w + negativeButton: left shift + positiveButton: space + altNegativeButton: + altPositiveButton: gravity: 3 dead: 0.001 sensitivity: 3 @@ -38,45 +38,45 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Fire1 + m_Name: Horizontal descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: left ctrl + positiveButton: altNegativeButton: - altPositiveButton: mouse 0 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 + altPositiveButton: + gravity: 0 + dead: 0.19 + sensitivity: 1 snap: 0 invert: 0 - type: 0 + type: 2 axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Fire2 + m_Name: Vertical descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: left alt + positiveButton: altNegativeButton: - altPositiveButton: mouse 1 - gravity: 1000 - dead: 0.001 - sensitivity: 1000 + altPositiveButton: + gravity: 0 + dead: 0.19 + sensitivity: 1 snap: 0 - invert: 0 - type: 0 - axis: 0 + invert: 1 + type: 2 + axis: 1 joyNum: 0 - serializedVersion: 3 - m_Name: Fire3 + m_Name: Throttle descriptiveName: descriptiveNegativeName: - negativeButton: - positiveButton: left shift - altNegativeButton: - altPositiveButton: mouse 2 + negativeButton: down + positiveButton: up + altNegativeButton: s + altPositiveButton: w gravity: 1000 dead: 0.001 sensitivity: 1000 @@ -86,23 +86,23 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Jump + m_Name: Throttle descriptiveName: descriptiveNegativeName: - negativeButton: - positiveButton: space - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 + negativeButton: down + positiveButton: up + altNegativeButton: s + altPositiveButton: w + gravity: 0 + dead: 0.19 + sensitivity: 1 snap: 0 invert: 0 - type: 0 - axis: 0 + type: 2 + axis: 2 joyNum: 0 - serializedVersion: 3 - m_Name: Mouse X + m_Name: Look X descriptiveName: descriptiveNegativeName: negativeButton: @@ -118,7 +118,7 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Mouse Y + m_Name: Look Y descriptiveName: descriptiveNegativeName: negativeButton: @@ -134,23 +134,7 @@ InputManager: 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 + m_Name: Look X descriptiveName: descriptiveNegativeName: negativeButton: @@ -159,14 +143,14 @@ InputManager: altPositiveButton: gravity: 0 dead: 0.19 - sensitivity: 1 + sensitivity: 0.5 snap: 0 invert: 0 type: 2 - axis: 0 + axis: 3 joyNum: 0 - serializedVersion: 3 - m_Name: Vertical + m_Name: Look Y descriptiveName: descriptiveNegativeName: negativeButton: @@ -175,50 +159,34 @@ InputManager: altPositiveButton: gravity: 0 dead: 0.19 - sensitivity: 1 + sensitivity: 0.5 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 + axis: 4 joyNum: 0 - serializedVersion: 3 - m_Name: Fire2 + m_Name: Roll descriptiveName: descriptiveNegativeName: - negativeButton: - positiveButton: joystick button 1 - altNegativeButton: - altPositiveButton: - gravity: 1000 - dead: 0.001 - sensitivity: 1000 + negativeButton: joystick button 4 + positiveButton: joystick button 5 + altNegativeButton: q + altPositiveButton: e + gravity: 0 + dead: 0.19 + sensitivity: 1 snap: 0 invert: 0 type: 0 - axis: 0 + axis: 27 joyNum: 0 - serializedVersion: 3 - m_Name: Fire3 + m_Name: Select descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: joystick button 2 + positiveButton: joystick button 0 altNegativeButton: altPositiveButton: gravity: 1000 @@ -230,61 +198,13 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Jump + m_Name: Toggle descriptiveName: descriptiveNegativeName: negativeButton: positiveButton: joystick button 3 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 + altPositiveButton: f gravity: 1000 dead: 0.001 sensitivity: 1000