#lmao, i'm not the best at writing neat

1 messages · Page 1 of 1 (latest)

charred moon
#

So you're only setting isCrouched via the inspector right now?

remote cobalt
#

from here ``` if(GetComponent<CapsuleCollider>().height == CrouchHeight)
{
Crouching = false;
isCrouched = true;
}

    if (GetComponent<CapsuleCollider>().height == OriginalHeight)
    {
        Standing = false;
        isCrouched = false;
    }```
charred moon
#

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());
        }
remote cobalt
#

should i base it on player velocity instead?

charred moon
#

Your || conditions are not complete, and this runs in update() so every frame it's checking your statements.

remote cobalt
charred moon
#

Can you open an empty C# console project?

#

or just debug this

#

is fine

remote cobalt
#

put a debug in each code where its setting its false?

charred moon
#

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./

remote cobalt
#

I am true and running

charred moon
#

Ok perfect. What would you expect if you made isCrouchedTest false?

remote cobalt
#

I am false?

charred moon
#

Try it out

remote cobalt
#

Nope still I am true and running

charred moon
#

Ok do you understand why your conditionals are not correct now?

remote cobalt
#

Wouldn't i put else if(IsCrouched)?

charred moon
#

It's the same as what you have here:

charred moon
#

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");
}
remote cobalt
#

Okay, i will try that.

charred moon
#

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.

charred moon
#

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:

remote cobalt
#

Okay i'm going to test it right now.

charred moon
#

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.

charred moon
remote cobalt
#

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

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.

remote cobalt
#

I found the issue, i'm checking if one of them == 0 ,instead of both.

#

@charred moon

charred moon
#

nice 🙂

remote cobalt
#

Yep, that fixed it, thanks for helping me, i definitely wouldn't have gotten it on my own.