Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question My RayCast is not hitting properly?!

Discussion in 'Editor & General Support' started by JavaForever, Dec 23, 2022.

  1. JavaForever

    JavaForever

    Joined:
    Jul 10, 2020
    Posts:
    3
    As shown below in the image I have a RayCast starting from my player and going down.

    upload_2022-12-23_16-14-54.png

    I am using this RayCast to ground the player but my isGrounded bool only gets set to true when I remove the layer mask.

    upload_2022-12-23_16-16-38.png

    I have double checked that all my ground objects are on the correct layer for my layer mask.

    Please Help?!
     
  2. bachus00

    bachus00

    Joined:
    Apr 15, 2022
    Posts:
    4
    and what is your layerMask set to?
     
  3. JavaForever

    JavaForever

    Joined:
    Jul 10, 2020
    Posts:
    3
    My layerMask is set to a layer that I created (called "Ground") and added all the objects that need to ground the player.
     
  4. bachus00

    bachus00

    Joined:
    Apr 15, 2022
    Posts:
    4
    I assume you have collider on the ground?
     
  5. JavaForever

    JavaForever

    Joined:
    Jul 10, 2020
    Posts:
    3
    There is a collider on the ground, the gounding works when the layerMask is excluded from the RayCast, but I need to be able to differentiate between the ground and other objects for proper grounding.
     
  6. CosmicStud

    CosmicStud

    Joined:
    Jun 13, 2017
    Posts:
    55
    I literally went through hell trying to figure out why my raycast were not working then I discovered my rigidbody had isKinematic turned on... Perhaps the ray is interacting another collider, try to determine what object is hit with a Debug.Log with the layer mask turned off, or perhaps add the trigger parameter and set to false in the Raycast method