Hi,
I’m having some problems with making my character switch between prone, crouch and stand stances. I’m trying to copy the stance system from MGS:V where all the changes are made by either pressing or holding F.
Currently my code’s problem is that I can’t switch back to stand mode after going either crouch or prone. I believe this is due to the button presses function changes according to a bool that it’s supposed to change.
The code is supposed to work like this:
F press while standing: crouch
F press while crouch: stand
F press while prone: crouch
F hold while stand: prone
F hold while crouch: prone
F hold while prone: stand
The cLongPress bool is supposed to count the time the key is pressed and it seems to work fine and the reason i used keyUp for pressing C (not holding) is so that the timer actually has a change to go to to the cRequeredPressTime
public float cPressTimeRequered = 0.5f;
public float cPressTime = 0;
public bool cLongPress = false;
public bool isGrounded;
public bool isStanding;
public bool isCrouched = false;
public bool isProne = false;
// Use this for initialization
void Start()
{
isStanding = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.C))
{
cPressTime += Time.deltaTime;
}
if (Input.GetKeyUp(KeyCode.C))
{
cPressTime = 0;
}
//To Stand
if (Input.GetKeyUp(KeyCode.C) && cLongPress == false && isCrouched)
{
isStanding = true;
isCrouched = false;
isProne = false;
}
if (Input.GetKey(KeyCode.C) && cLongPress == true && isProne)
{
isStanding = true;
isCrouched = false;
isProne = false;
}
//To Crouch
if (Input.GetKeyUp(KeyCode.C) && cLongPress == false && isStanding)
{
isStanding = false;
isCrouched = true;
isProne = false;
}
if (Input.GetKeyUp(KeyCode.C) && cLongPress == false && isProne)
{
isStanding = false;
isCrouched = true;
isProne = false;
}
//To Prone
if (Input.GetKey(KeyCode.C) && cLongPress == true && isStanding)
{
isStanding = false;
isCrouched = false;
isProne = true;
}
if (Input.GetKey(KeyCode.C) && cLongPress == true && isCrouched)
{
isStanding = false;
isCrouched = false;
isProne = true;
}
}
The only solution that I’ve been able to find was to use animations to change the stance but I would prefer to make the script somewhat independent of the animator.,