this code is about raycast.
Physics.Raycast(transform.position, -Vector3.up * gravity, distToGround + 0.1f
as far i know raycast have starting point , direction and hit distance… is disToGround + 0.1f hit distance.?? can anyone explain me in brief.
Physics.Raycast(transform.position, -Vector3.up * gravity, distToGround + 0.1f
Well, first off, the example you provided isn’t the entire function call.
That aside, as you said, the third argument is the distance; rather, it’s the maximum length of the Raycast(). distToGround is a variable someone made for the call, so the intent with this particular Raycast() is to check from the character’s position toward the ground (with a gravity modifier, presumably 1 or -1 in case gravity is reversed in the game’s context), up to a maximum distance (distToGround) to determine whether the character is standing on the ground.
Edit: Furthermore, the + 0.1f
is there for padding. If you have a capsule collider character with a center 1 unit from the ground, then fire a Raycast, a 1.0-length Raycast has a chance of unexpectedly falling short due to rounding errors, whereas 1.1-length, after adding the padding, ensures it will hit the ground more reliably.
thanks a lot. @Eno-Khaon but i dont know what’s wrong in my code still i am not able to get desire answer. i have animation of landing and i want animation to get triggered as soon as my character reach certain height. but nothings happens. instead my character jump at height and then get stuck mid air and the stuck pose moves mid air by “vertical” and “horizontal” keys. is something wrong with this code. i know it is just the snippet of the code. if you need i can post the full code. void jumpDown() { if (Physics.Raycast(transform.position, Vector3.down, height)) { anim.SetBool("jumpDown", true); } else { anim.SetBool("jumpDown", false); } }