OnGround Raycast not working when after scaling fps character

I am trying to make a FPS Game. In the Movement.cs. The Raycast starts from the center of the Capsule (player’s transform.position) and is sent towards Vector3.down, with the limit of playerHeight / 2 + 0.1f, where playerHeight is the height of the CapsuleCollider of the player (Capsule).

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
   
    public class checkJump : MonoBehaviour
    {
        private Rigidbody rb;
        private float playerHeight = 2f;
        private bool isOnGround;
        private float jumpSpeed = 400f;
   
        void Start() {
            rb = GetComponent<Rigidbody>();
        }
        void Update()
        {
            isOnGround = Physics.Raycast(transform.position, Vector3.down, playerHeight / 2 + 0.1f);
            Jump();
            Debug.Log(isOnGround);
        }
   
        void Jump() {
            if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
            {
                rb.AddForce(Vector3.up * jumpSpeed * Time.deltaTime, ForceMode.Impulse);
           
            }
        }
    }

I disabled all other scripts except “checkJump.cs” one. And when I set the scale value to (4,4,3) or something else, it shows me false in the console and nor does the player Jump when I press Enter. But when I set the scale value to (1,1,1) it shows true. In both cases, the player is on the surface of the ground.

Use CapsuleCollider.height instead of a hard coded value.

void Start() {
    playerHeight = GetComponent<CapsuleCollider>().height;

Tried it, no change.

7541425--931606--onescale.png
7541425--931609--otherscale.png

… that’s still cached once at the start. You’ll need to sample the value in Update or every time you actually change the scale.

The player height always remains the same, 2f. No matter how much you scale the capsule. And besides, I don’t have to scale the capsule in-game.
ANYWAYS The problem is solved

playerHeight = GetComponent<CapsuleCollider> * transform.localScale.y;
//This works