Skip to content

Commit 78dcc42

Browse files
committed
Added the ability to run for keyboard players
1 parent fb54d08 commit 78dcc42

File tree

5 files changed

+372
-274
lines changed

5 files changed

+372
-274
lines changed

UOP1_Project/Assets/Prefabs/GameplayEssentials/CameraSystem.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ MonoBehaviour:
782782
inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
783783
mainCamera: {fileID: 8745341642014614481}
784784
freeLookVCam: {fileID: 8745341641394998849}
785-
speed: 1
785+
speed: 2
786786
_cameraTransformAnchor: {fileID: 11400000, guid: bc205269957643647a8b5f98f028f9fb,
787787
type: 2}
788788
_frameObjectChannel: {fileID: 11400000, guid: 2723b3f59f7ede3498fe7e385d2bb6ee,

UOP1_Project/Assets/Scripts/Characters/Protagonist.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Protagonist : MonoBehaviour
1717
[HideInInspector] public Vector3 movementInput; //Initial input coming from the Protagonist script
1818
[HideInInspector] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
1919
[HideInInspector] public ControllerColliderHit lastHit;
20+
[HideInInspector] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
2021

2122
private void OnControllerColliderHit(ControllerColliderHit hit)
2223
{
@@ -30,6 +31,8 @@ private void OnEnable()
3031
_inputReader.jumpCanceledEvent += OnJumpCanceled;
3132
_inputReader.moveEvent += OnMove;
3233
_inputReader.extraActionEvent += OnExtraAction;
34+
_inputReader.startedRunning += OnStartedRunning;
35+
_inputReader.stoppedRunning += OnStoppedRunning;
3336
//...
3437
}
3538

@@ -40,6 +43,8 @@ private void OnDisable()
4043
_inputReader.jumpCanceledEvent -= OnJumpCanceled;
4144
_inputReader.moveEvent -= OnMove;
4245
_inputReader.extraActionEvent -= OnExtraAction;
46+
_inputReader.startedRunning -= OnStartedRunning;
47+
_inputReader.stoppedRunning -= OnStoppedRunning;
4348
//...
4449
}
4550

@@ -70,6 +75,11 @@ private void RecalculateMovement()
7075
Debug.LogWarning("No gameplay camera in the scene. Movement orientation will not be correct.");
7176
movementInput = new Vector3(_previousMovementInput.x, 0f, _previousMovementInput.y);
7277
}
78+
79+
// This is used to set the speed to the maximum if holding the Shift key,
80+
// to allow keyboard players to "run"
81+
if (isRunning)
82+
movementInput.Normalize();
7383
}
7484

7585
//---- EVENT LISTENERS ----
@@ -89,6 +99,10 @@ private void OnJumpCanceled()
8999
jumpInput = false;
90100
}
91101

102+
private void OnStoppedRunning() => isRunning = false;
103+
104+
private void OnStartedRunning() => isRunning = true;
105+
92106
// This handler is just used for debug, for now
93107
private void OnExtraAction()
94108
{

0 commit comments

Comments
 (0)