Raycast are inacurate for ground detection?

Hey guys !

I’m currently doing a ground detection by using Raycast, i’l trying to see if a part is touching the ground.
I’m raycasting every frame in a HeartBeat function.

However i’m running in an issue where my part detect the ground sometimes faster or sometimes slower. I would like my ray to be all the times perfect so that the position of the detection is always at the same times however it’s not the case. When i’m putting my part in the sky and waiting for it to touch the ground, the ray isn’t always detecting the ground at the same position/time. That’s a problem for me however idk how i could fix that so if you hafve any ideas it would be cool !

Thanks !

RayCasts are instant, no matter the distance. The time could be delayed by the function you are running prior to firing the raycast

Can’t reproduce, can you provide us a snippet of where you’re firing the ray to see what’s happening? Probably you’re performing a yielding action before raycasting as the above post said.


So here it’s what i’m doing basically however when i play and wait to touch the ground when i check the position of the part it’s not always the same Y position when i just replay the game. And that’s shouldn’t be normal because the ground should always be on the same y position.

You should do this ray cast from the client. Pretty much anything involving player movement should be client side or you’ll end up with wonky values.

Uhm it’s already client side so

The code up there is running during Heartbeat. That’s on the server.

Uhm ? tho it’s in a local script so it’s client right ?

It should be giving you an error if your trying to connect to heartbeat from a local script.

Really ? weird ? But what i can use that isn’t heartbeat then ?

RenderStepped event. At priority after 300 (that’s character stuff)

RenderStepped is based on the fps of the client tho ? Couldn’t made it unaccurate when player is lagging ?

Its on the client, so the client calculates the physics for their own character.

Oh ok i’ll check that then thanks

Ok so i just tested by using HeartBeat in a local script and it does work

Interesting, I don’t remember it ever allowing that before.

Can you provide a video or place to reproduce what you’re experimenting? Everything seems fine with your code.


Do not let yourself be misinformed, please check how RunService actually works. Heartbeat can run in server and client.

RenderStepped should only be used for actions that really need to be performed before the frame renders, it needs to be carefully used for this kind of stuff to avoid having to deal with performance issues.

Ok i’m gonna make one to show you

I have checked. In the past I always received errors trying to use Heartbeat on the the client end.

This is quote from the API reference.

To avoid this, only use RenderStepped for code that works with the camera or character .

RayCast.rbxl (35.2 KB)
Here the place
In it you can see the part falling and it should print the position of the Part when it touch the ground but it’s never the same when you test multiple time