#lmao, i'm not the best at writing neat
1 messages · Page 1 of 1 (latest)
from here ``` if(GetComponent<CapsuleCollider>().height == CrouchHeight)
{
Crouching = false;
isCrouched = true;
}
if (GetComponent<CapsuleCollider>().height == OriginalHeight)
{
Standing = false;
isCrouched = false;
}```
oh shit theres 24 calls to it, thought the script said 3.
So these are probably your problems, amongst others that's too much for me to look at:
if (isCrouched && ControllerinUse && ((Input.GetAxis("Horizontal") != Mathf.Clamp(Input.GetAxis("Horizontal"), -0.5f, 0.5f) || (Input.GetAxis("Vertical") != Mathf.Clamp(Input.GetAxis("Vertical"), -0.5f, 0.5f)))))
{
StartCoroutine(isCrouch());
}
if((isCrouched && ControllerinUse && ((Input.GetAxis("Horizontal") == Mathf.Clamp(Input.GetAxis("Horizontal"), -0.5f, 0.5f) || (Input.GetAxis("Vertical") == Mathf.Clamp(Input.GetAxis("Vertical"), -0.5f, 0.5f))))))
{
isCrouchWalking = false;
StopCoroutine(isCrouch());
}
if (isCrouched && KBMinUse && Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
{
StartCoroutine(isCrouch());
}
if(isCrouched && KBMinUse && Input.GetAxis("Horizontal") == 0 || Input.GetAxis("Vertical") == 0)
{
isCrouchWalking = false;
StopCoroutine(isCrouch());
}
should i base it on player velocity instead?
Your || conditions are not complete, and this runs in update() so every frame it's checking your statements.
I'm not fully sure what that means
How would i fix them?
put a debug in each code where its setting its false?
Put this in update:
bool isCrouchedTest = true;
bool KBMinUseTest = true;
int horizontalTest = 1;
int verticalTest = 1;
if (isCrouchedTest && KBMinUseTest && horizontalTest != 0 || verticalTest != 0)
{
Debug.Log("I am true and running");
}
else
{
Debug.Log("I am false");
}
Or jut put it in Start() so you dont spammed
Tell me what it prints./
I am true and running
Ok perfect. What would you expect if you made isCrouchedTest false?
I am false?
Try it out
Nope still I am true and running
Ok do you understand why your conditionals are not correct now?
Wouldn't i put else if(IsCrouched)?
It's the same as what you have here:
To be explicit, update the code I sent to be this...
bool isCrouchedTest = false;
bool KBMinUseTest = true;
int horizontalTest = 1;
int verticalTest = 1;
if (isCrouchedTest && KBMinUseTest && horizontalTest != 0 || isCrouchedTest && KBMinUseTest && verticalTest != 0)
{
Debug.Log("I am true and running");
}
else
{
Debug.Log("I am false");
}
Okay, i will try that.
now with isCrouchedTest set to false, what do you get?
Sorry, set isCrouchedTest to false.
You are checking if you're crouched and horizontal is not 0, to start the couroutine, but if isCrouched is false, but your || vertical != 0 is true, then you still start coroutine, which isn't what you want.
ugh wait, you do have it wrapped in parentheses i think, sorry there was just way too much to see. I think I just wasted your time 😦
I was going to say you either need to repeat the conditions or do:
bool isCrouched = false;
bool KBMinUse = true;
int horizontal = 1;
int vertical = 1;
if (isCrouched && KBMinUse && (horizontal != 0 || vertical != 0))
{
Console.WriteLine("I am true and running");
}
else
{
Console.WriteLine("I am false");
}
but to go back, the bool flickering, is definitely the cause of conflicting statements changing the bool at the same time.
It's all happening in Update() so every frame, with all your conditions they're being evaluated and constantly changing (or repetitively being set).
And I'm gonna stop because there's too much here and i dont wanna lead you down the wrong path, but I double back lol. You are missing parantheses:
I SEE WHAT YOU MEAN NOW
Okay i'm going to test it right now.
yea sorry im all out of it today.
it's likely you have issues elsewhere due to how many times you're setting the bools etc in Update. But good place to start would be double checking these conditionals.
like this? https://i.imgur.com/QnZHSMX.png
yeah
Its still flickering, and it looks to be this, thats doing it. if(isCrouched && KBMinUse && (Input.GetAxis("Horizontal") == 0 || Input.GetAxis("Vertical") == 0)) { //isCrouchWalking = false; StopCoroutine(isCrouch()); }
It works fine when clicking W and D
@charred moon
yeah prob something with all the times you're setting and calling your bools/coroutines. Really this way is just not manageable.
Take your time, log, and look through it. Really all anyone can do.
I found the issue, i'm checking if one of them == 0 ,instead of both.
@charred moon
nice 🙂
Yep, that fixed it, thanks for helping me, i definitely wouldn't have gotten it on my own.