@@ -17,6 +17,7 @@ public class Protagonist : MonoBehaviour
17
17
[ HideInInspector ] public Vector3 movementInput ; //Initial input coming from the Protagonist script
18
18
[ HideInInspector ] public Vector3 movementVector ; //Final movement vector, manipulated by the StateMachine actions
19
19
[ HideInInspector ] public ControllerColliderHit lastHit ;
20
+ [ HideInInspector ] public bool isRunning ; // Used when using the keyboard to run, brings the normalised speed to 1
20
21
21
22
private void OnControllerColliderHit ( ControllerColliderHit hit )
22
23
{
@@ -30,6 +31,8 @@ private void OnEnable()
30
31
_inputReader . jumpCanceledEvent += OnJumpCanceled ;
31
32
_inputReader . moveEvent += OnMove ;
32
33
_inputReader . extraActionEvent += OnExtraAction ;
34
+ _inputReader . startedRunning += OnStartedRunning ;
35
+ _inputReader . stoppedRunning += OnStoppedRunning ;
33
36
//...
34
37
}
35
38
@@ -40,6 +43,8 @@ private void OnDisable()
40
43
_inputReader . jumpCanceledEvent -= OnJumpCanceled ;
41
44
_inputReader . moveEvent -= OnMove ;
42
45
_inputReader . extraActionEvent -= OnExtraAction ;
46
+ _inputReader . startedRunning -= OnStartedRunning ;
47
+ _inputReader . stoppedRunning -= OnStoppedRunning ;
43
48
//...
44
49
}
45
50
@@ -70,6 +75,11 @@ private void RecalculateMovement()
70
75
Debug . LogWarning ( "No gameplay camera in the scene. Movement orientation will not be correct." ) ;
71
76
movementInput = new Vector3 ( _previousMovementInput . x , 0f , _previousMovementInput . y ) ;
72
77
}
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 ( ) ;
73
83
}
74
84
75
85
//---- EVENT LISTENERS ----
@@ -89,6 +99,10 @@ private void OnJumpCanceled()
89
99
jumpInput = false ;
90
100
}
91
101
102
+ private void OnStoppedRunning ( ) => isRunning = false ;
103
+
104
+ private void OnStartedRunning ( ) => isRunning = true ;
105
+
92
106
// This handler is just used for debug, for now
93
107
private void OnExtraAction ( )
94
108
{
0 commit comments