Skip to content

Commit

Permalink
Separate touch based turning to prevent drags registering as mouse mo…
Browse files Browse the repository at this point in the history
…vement at the same time and causing erratic turn behavior
  • Loading branch information
JosiahJack committed Sep 2, 2023
1 parent bd6ae8b commit fabd1d9
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions Assets/Scripts/MouseLookScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Start (){
Cursor.lockState = CursorLockMode.None;
inventoryMode = false; // Start with inventory mode turned off.
if (Application.platform == RuntimePlatform.Android) {
inventoryMode = true;
ForceInventoryMode();
shootModeButton.SetActive(true);
} else {
shootModeButton.SetActive(false);
Expand Down Expand Up @@ -210,6 +210,7 @@ void Update() {
}
KeyboardTurn();
KeyboardLookUpDn();
TouchLook();
if (inCyberSpace) { // Barrel roll!
if (GetInput.a.LeanLeft()) {
playerCapsuleTransform.RotateAround(
Expand Down Expand Up @@ -277,12 +278,6 @@ public void Mouselook() {
// Handle thumbstick input from a controller.
Vector2 rightThumbstick = new Vector2(Input.GetAxisRaw("JoyAxis4"), // Horizontal Left < 0, Right > 0
Input.GetAxisRaw("JoyAxis5") * -1f); // Vertical Down > 0, Up < 0 Inverted

Vector2 rightTouchstick = GetInput.a.rightTS.Coordinate();
rightThumbstick += rightTouchstick;

Debug.Log("rightThumbstick: " + rightThumbstick.ToString());

// X
float signX = rightThumbstick.x > 0.0f ? 1.0f
: rightThumbstick.x < 0.0f ? -1.0f : 0f;
Expand Down Expand Up @@ -449,6 +444,37 @@ public void SetCameraCullDistances() {
}
playerCamera.layerCullDistances = cameraDistances; // Cull anything beyond 79f except for sky layer.
}

void TouchLook() {
Vector2 rightTouchstick = GetInput.a.rightTS.Coordinate();
if (rightTouchstick.x < 0f {
yRotation -= keyboardTurnSpeed * rightTouchstick.x;
playerCapsuleTransform.localRotation = Quaternion.Euler(0f, yRotation, 0f);
} else if (rightTouchstick.x > 0f {
yRotation += keyboardTurnSpeed * rightTouchstick.x;
playerCapsuleTransform.localRotation = Quaternion.Euler(0f, yRotation, 0f);
}

if (rightTouchstick.y < 0f {
if ((inCyberSpace && Const.a.InputInvertCyberspaceLook) || (!inCyberSpace && Const.a.InputInvertLook))
xRotation -= keyboardTurnSpeed;
else
xRotation += keyboardTurnSpeed;

if (!inCyberSpace) xRotation = Mathf.Clamp(xRotation, -90f, 90f); // Limit up and down angle.
transform.localRotation = Quaternion.Euler(xRotation,0f,
transform.localRotation.z);
} else if (rightTouchstick.y > 0f {
if ((inCyberSpace && Const.a.InputInvertCyberspaceLook) || (!inCyberSpace && Const.a.InputInvertLook))
xRotation += keyboardTurnSpeed * rightTouchstick.y;
else
xRotation -= keyboardTurnSpeed * rightTouchstick.y;

if (!inCyberSpace) xRotation = Mathf.Clamp(xRotation, -90f, 90f); // Limit up and down angle.
transform.localRotation = Quaternion.Euler(xRotation, 0f,
transform.localRotation.z);
}
}

void KeyboardTurn() {
if (GetInput.a.TurnLeft()) {
Expand All @@ -458,6 +484,8 @@ void KeyboardTurn() {
yRotation += keyboardTurnSpeed;
playerCapsuleTransform.localRotation = Quaternion.Euler(0f, yRotation, 0f);
}

Vector2 rightTouchstick = GetInput.a.rightTS.Coordinate();
}

void KeyboardLookUpDn() {
Expand Down

0 comments on commit fabd1d9

Please sign in to comment.