Skip to content

Commit

Permalink
Add toggleable crouch, add extra gamepad buttons for zoom+crouch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku committed May 18, 2024
1 parent bd77e85 commit 44b4974
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 29 deletions.
73 changes: 62 additions & 11 deletions Assets/ScriptableObjects/Input/PlayerControls.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@
"interactions": "",
"initialStateCheck": false
},
{
"name": "CrouchToggle",
"type": "Button",
"id": "8d731947-226e-4543-a97c-a83b3391ea36",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Zoom",
"type": "Button",
Expand All @@ -548,6 +557,15 @@
"interactions": "",
"initialStateCheck": false
},
{
"name": "ZoomToggle",
"type": "Button",
"id": "1b173d76-269b-47ac-971a-f7c2a2b9a9a0",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Interact",
"type": "Button",
Expand Down Expand Up @@ -716,7 +734,7 @@
{
"name": "",
"id": "14967268-3847-4e31-b556-017d17d7d911",
"path": "<Gamepad>/leftTrigger",
"path": "<Gamepad>/leftShoulder",
"interactions": "",
"processors": "",
"groups": "Gamepad",
Expand Down Expand Up @@ -760,7 +778,7 @@
{
"name": "",
"id": "934f0261-5d67-4c99-babd-a34f558f6b2c",
"path": "<Gamepad>/rightStickPress",
"path": "<Gamepad>/leftTrigger",
"interactions": "",
"processors": "",
"groups": "Gamepad",
Expand All @@ -770,34 +788,67 @@
},
{
"name": "",
"id": "8092a7ef-355c-48f6-b000-0d843fc6f278",
"id": "f3cca0d8-5138-4ddf-a699-40a00e99144d",
"path": "<Keyboard>/f",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "2618ead8-8aa7-4287-9949-2b69a81828b9",
"path": "<Gamepad>/buttonWest",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "10d91971-d53d-46b9-a9d7-1cd214a97fa4",
"path": "<Gamepad>/rightStickPress",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "ZoomToggle",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "769f8717-a4f7-47cc-9ea3-716b5ce90378",
"path": "<Gamepad>/buttonNorth",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Zoom",
"action": "ZoomToggle",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f3cca0d8-5138-4ddf-a699-40a00e99144d",
"path": "<Keyboard>/f",
"id": "5ac8de42-d1b6-4205-8c51-f43460047250",
"path": "<Gamepad>/leftStickPress",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Interact",
"groups": "Gamepad",
"action": "CrouchToggle",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "2618ead8-8aa7-4287-9949-2b69a81828b9",
"path": "<Gamepad>/buttonWest",
"id": "057e28d0-2037-49e8-ade4-d644fc12679d",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Interact",
"action": "CrouchToggle",
"isComposite": false,
"isPartOfComposite": false
}
Expand Down
43 changes: 32 additions & 11 deletions Assets/Scripts/Control&Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class InputManager : MonoBehaviour
public bool IsMouseAndKeyboard => isMouseAndKeyboard;

public bool ZoomActive = false;
public bool CrouchActive = false;

void Start()
{
Expand Down Expand Up @@ -88,8 +89,12 @@ public void AddListeners()
playerInput.actions["Fire"].canceled += Fire;
playerInput.actions["Crouch"].performed += Crouch;
playerInput.actions["Crouch"].canceled += Crouch;
playerInput.actions["CrouchToggle"].performed += CrouchToggle;
playerInput.actions["CrouchToggle"].canceled += CrouchToggle;
playerInput.actions["Zoom"].performed += Zoom;
playerInput.actions["Zoom"].canceled += Zoom;
playerInput.actions["ZoomToggle"].performed += ZoomToggle;
playerInput.actions["ZoomToggle"].canceled += ZoomToggle;
playerInput.actions["Look"].performed += Look;
playerInput.actions["Look"].canceled += Look;

Expand Down Expand Up @@ -225,24 +230,40 @@ private void Fire(InputAction.CallbackContext ctx)

private void Crouch(InputAction.CallbackContext ctx)
{
if (ctx.performed) { onCrouchPerformed?.Invoke(ctx); return; }
if (ctx.performed) {
CrouchActive = true;
onCrouchPerformed?.Invoke(ctx);
return;
}
CrouchActive = false;
onCrouchCanceled?.Invoke(ctx);
}

private void Zoom(InputAction.CallbackContext ctx)
private void CrouchToggle(InputAction.CallbackContext ctx)
{
if (isMouseAndKeyboard)
if (ctx.performed)
{
if (ctx.performed) {
ZoomActive = true;
onZoomPerformed?.Invoke(ctx);
return;
}
ZoomActive = false;
onZoomCanceled?.Invoke(ctx);
return;
CrouchActive = !CrouchActive;
if (!CrouchActive) { onCrouchCanceled?.Invoke(ctx); return; }
onCrouchPerformed?.Invoke(ctx);
}
}

private void Zoom(InputAction.CallbackContext ctx)
{
if (ctx.performed)
{
ZoomActive = true;
onZoomPerformed?.Invoke(ctx);
return;
}
ZoomActive = false;
onZoomCanceled?.Invoke(ctx);
return;
}

private void ZoomToggle(InputAction.CallbackContext ctx)
{
if (ctx.performed)
{
ZoomActive = !ZoomActive;
Expand Down
9 changes: 2 additions & 7 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,10 @@ private void OnCrouch(InputAction.CallbackContext ctx)
gunHolder.transform.localPosition = new Vector3(gunHolder.transform.localPosition.x, localGunHolderHeight, gunHolder.transform.localPosition.z);
}

if (ctx.performed)
{
if (inputManager.CrouchActive)
StartCrouching();
}

if (ctx.canceled)
{
else
StopCrouching();
}
}

private void StartCrouching()
Expand Down

0 comments on commit 44b4974

Please sign in to comment.