Search Unity

Getting unstable numbers when raycasting down

Discussion in 'Physics' started by MPettay, Dec 1, 2019.

  1. MPettay

    MPettay

    Joined:
    Nov 14, 2019
    Posts:
    1
    I am trying to use Raycast to get the current height of my player while jumping to set a trigger in animation but the number drops to zero as the updates happen... is there a way to stabilize this number so that doesn't happen.

    Here is my code


    // Check height above ground
    RaycastHit hit;
    Ray downRay = new Ray(transform.position, Vector3.down);
    if (Physics.Raycast(downRay, out hit))
    {

    toGround = hit.distance;
    // Check if in the Air
    if (toGround >= 1.4)
    {
    GameManager.instance.animPlayer.SetBool("inAir", true);
    }
    else
    {
    GameManager.instance.animPlayer.SetBool("inAir", false);
    }
    GameManager.instance.animPlayer.SetFloat("height", toGround);
    }