I want to edit the FirstPersonController script to make it impossible to sprint backwards.
I found the part of the script talking about sprinting and it looked like this :
private void GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
As you can see, there’s a line saying that the character will walk if the LeftShift key isn’t pressed (Line 12 on the post, line 213 on the original and complete file).
The line in question is this : m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
The problem is that I can’t find the way to add another propertie for m_IsWalking. I want to make it walk when the LeftShift and S keys are pressed togheter. It seems like bool stuffs aren’t allowing multiples properties at a time.
You’ll want to include the ! before left shift. It is checking to see if you are sprinting. If you are (true), then the ! instructs your m_IsWalking bool to be false (opposite of sprint’s true output). I would try something like thism_IsWalking = !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.S);:
I did not got what you were saying but you are using out with speed. And the methods is returning nothing. You should always return a value unless you want to return more that a value.
THANK YOU! It worked. It may be because of those two line || you put between the two conditions. What do they mean? It may be useful for my future codes.