Ok, so I’m setting up a basic jump script and I want the jump counter (how long the charcter jumps before he falls) to reset to zero every time he hits the ground. So basically I’m wondering how I can setup a ray that casts down and if it is less than like 2.0 or somthing then the jump counter is set to 0. How would I get the distance to the ground with Raycasting?
Can someone please help me? I really want to figure this out…
If your character is using a CharacterController for collision, I would recommend using it rather than a ray - specifically the isGrounded variable or the OnControllerColliderHit() event.
My character is not using the character controller… it’s using rigid body with freeze rotation enabled.
You just need to use the variant of Physics.Raycast that returns a RaycastHIt result. The RaycastHit contains a distance value, which is simply the distance along the ray where the hit occurred.
What exactly is that varient? I’m a newbie so could you just make an example line of code using it? That wouldbe awsome. Thanks.
would it be: if (Physics.Raycast(length) < 1.0)
What exactly is that varient? I’m a newbie so could you just make an example line of code using it? That wouldbe awsome. Thanks.
would it be: if (Physics.Raycast(length) < 1.0)
I figured it out ![]()