The above image shows the setup I am using. The larger sphere collider is the ground collider which the player uses to smoothly move over objects such as stairs. The smaller sphere collider is the jump detecter. Its purpose is to test if the ground / a surface the player can jump on is directly beneath the player. I have set the larger sphere to ignore raycasts buy when I use:
private void Update()
{
UpdateCursorAndMobility();
rotUD = Mathf.Clamp(rotUD, -80, 80);
playerNeck.transform.localEulerAngles = new Vector3(-rotUD, 0, 0);
//Check if the player is touching a surface they can jump on:
RaycastHit hit;
grounded = Physics.SphereCast(jumpTester.transform.position, 0.65f, Vector3.down, out hit, 0.1f);
if (Input.GetKeyDown(KeyCode.P))
{
developerMode = !developerMode;
}
if(mobile == true)
{
MovementControls();
}
if(playerData.health > 0)
{
UIControls();
}
}
The value “grounded” always remains false even if the player is touching the ground.
Note that the collider radius of the jump detector is set to 0.3. The jump detector is also a “Is Trigger” collider.
Thanks in advanced.