0
\$\begingroup\$
    if (SimpleInput.GetButtonDown(jumpButton) && IsGrounded())
    {
        rb.AddForce(0f, 8f, 0f, ForceMode.Impulse);
    }

bool IsGrounded()
    {
        return Physics.CheckCapsule(Char_Collider.bounds.center, new Vector3(Char_Collider.bounds.center.x, Char_Collider.bounds.min.y, Char_Collider.bounds.center.z), Char_Collider.radius * 0.27f, GroundLayers);
    }

I've multiplied Char_Collider.radius with 0.27f 'cause in the tutorial that guy said You need to multiply this with %90 of your character's actual size That might be the problem because i don't actually know my character's size, i've made it in blender and scaled it down at the unity.

So if you look at the inspector panel you'll see it's 0.1 0.1 0.1 but it's actually not. I tried to spawn a cube and match them together roughly, cube's size was 0.3 1.2 0.3, that's way the number is 0.27f 'cause i just simply calculated it with the 0.3.

And finally my problem is:

I get return values from IsGrounded delayed, sometimes doesn't even get a value. Like example when i jump, sometimes it returns the value of IsGrounded False when i'm just about the hit the ground, and sometimes it doesn't returns the value of IsGrounded False. Because of this i can't make jump animation properly.

This is my HandleAnimation() method (I call that from FixedUpdate()):

void HandleAnimation()
{
    if (!IsGrounded())
    {
        anim.SetBool("Jumping", true);
    }
    else
    {
        anim.SetBool("Jumping", false);
    }
}

And this is my animator:

Animator

I am also adding those because sometimes when IsGrounded() returns false, animation doesn't works.

\$\endgroup\$
  • \$\begingroup\$ We have gobs of existing Q&A about performing ground checks. Can you show us how you've tried implementing the solutions from these existing questions? I'm betting at least one of them will work for you, and if not, we can troubleshoot the particular issue you're having with it. \$\endgroup\$ – DMGregory Jun 10 at 11:04
  • \$\begingroup\$ I've red all of the stuff that is related to mine. But those are not helping. Btw I've edited my question with new stuff you should check it. \$\endgroup\$ – AmonRa's Channel Jun 10 at 13:05
  • \$\begingroup\$ In what specific way is it not helping? Without showing us how you've tried to apply this advice (like raycasts or spherecasts) and what went wrong, we're liable to just repeat the same kinds of tips that you've already deemed unhelpful. Help us understand what's so different about your case that the hundreds of tutorials that worked for other developers don't work for you, then we can try to fix that specific issue. \$\endgroup\$ – DMGregory Jun 10 at 13:09
  • \$\begingroup\$ Raycasts are working fine i don't think that's the problem but it might be about the IsGrounded(). I'm just not feeling it's the right way to calculate because it has delay, i think it doesn't calculate it everyframe but maybe 30fps don't have any idea. The thing that's not working for me is animation, it's not applied when jumping but it does sometimes, it's simply RNG. I'm thinking maybe it's because of my animator or the HandleAnimation() code. I'm still researching here and the youtube for that animation problem, but there is nothing so far. \$\endgroup\$ – AmonRa's Channel Jun 10 at 13:48
0
\$\begingroup\$

According to my tests and researches my problem isn't the IsGrounded or raycasting, it's my jumpButton! I'll post an another question about that and link it to here if you guys want to check out.

So this IsGrounded() method is fine you can try it if this is your problem. Just make sure when multiplying Char_Collider.radius with 0.27f, You need to multiply it with your character's Actual Size not the Collider's Size.

\$\endgroup\$
  • \$\begingroup\$ Please accept your answer \$\endgroup\$ – Mohammad Zamanian Jun 12 at 12:00
  • \$\begingroup\$ I couldn't at the first time 'cause i needed to wait 40minutes but there you go \$\endgroup\$ – AmonRa's Channel Jun 12 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.