I’m trying to Blockcast below a custom character every single frame to figure out their Y level.
However, every once in a while when moving along ramps, the Resulting position from the Blockcast will yield an absurd result that is far outside any object I have placed.
In my logs I’ve been printing the BlockCast Ray’s Position every frame along the ramp and there’s very clearly a value that in the 100’s of thousand even though I’m hitting a ramp smaller than 50 studs wide in all directions. (I also checked the hit object in the prints and it is in fact hitting the ramp when breaking)
I’ve tried many different changes and for some reason this occurs under very specific circumstances of block cast size, object position, object orientation, object size.
Here’s a small video showcasing the issue happening in real time, the little teleport upwards is because the Blockcasts Ray Result is returning the Y of the very top of the platforms bounding box. The X returns one of the edges of the bounding box and the Z returns something in the 100’s of thousands.
This bug appears to not happen when using SphereCasting, so it seems to be BlockCast specific.
Was doing some more testing and managed to get the issue again when printing BlockCasts position:
Getting completely wild results that have no relation to where I’m blockcasting
The only workaround for this weird instances are to ignore BlockCasts if the Z value goes outside the range of -100000 to 100000. Otherwise there’s no way to really catch the issue
Addendum, 100000 is not a safe distance,
Apparently it can give bad results nearby as well. I’m starting to think blockcasting is much too unstable to rely on.
We have not been able to reproduce the bug using the test file so far… In your debug output, can you also add the position and size of the block you are casting. If the same input always gives the incorrect result, it will help with narrowing down this bug.
Hi, I managed to repro the bug and here are my inputs in raw form:
local c = CFrame.new(380.157227, 266.249268, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
local s = Vector3.new(1.9500000476837158, 1.9500000476837158, 1.9500000476837158)
local d = Vector3.new(0, -13, 0)
local rayresult = workspace:BlockCast(c, s, d)
expected rayresult.position: ~382, ~263, ~0.97
actual rayresult.position: 396.5703125, 274.625, 4309.861328125
The hit object was a block (part):
position: 215.775, 125.1, 0.225
orientation: 0, 0, 38.075
size: 469.082, 12.431, 11.955
and obviously has cancollide enabled
and the blockcast has a rayparams that simply has RespectCanCollide set to true and nothing else.
Using these very specific inputs I have given, I can 100% reliably repro the bug