mojira.dev
MCPE-237014

Scripting raycast maxDistance doesn't go far enough for non-axis direction vectors

The bug

The maxDistance field in BlockRaycastOptions as used in some scripting APIs like dimension.getBlockFromRay limits the distance that the raycast will travel to find a block before giving up and returning undefined.

It works correctly when the provided (normalized) direction vector only has one of x, y, or z set to a non-zero value. However, if the vector does cross multiple axes, the raycast does not travel far enough before giving up. It’s not clear exactly what factor determines the actual distance traveled, but it is always less than the provided maxDistance.

How to reproduce

  1. Download and open the attached world. It contains a script that raycasts in all directions. Red spheres appear indicating the direction of each raycast, extending to a maximum distance of 5.0. A green sphere appears when getBlockFromRay found a hit.

  2. Walk around the glass circle and observe when the green circles appear.

Expected behavior

Anytime the red circles intersect with the glass, a green circle should appear indicating a raycast with that same maxDistance found the relevant block.

Observed behavior

In the cardinal directions, this occurs. In the other directions, the green circle does not appear until the red circles have deeply intersected with the glass, indicating that the raycast did not travel the distance specified.

Notes

The relevant script file has been attached for convenience.

[media][media]

Attachments

Comments 0

No comments.

tryashtar

(Unassigned)

Unconfirmed

Windows

26.3, 26.10.27 Preview, 26.20.20 Preview

Retrieved