Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
703 stars 80 forks source link

Ray inaccuracy when selecting/breaking blocks #107

Closed Ruixel closed 4 years ago

Ruixel commented 4 years ago

Bug Name

Ray inaccuracy when breaking/placing blocks

Describe the bug

When a user points their camera to the edge of a block, sometimes the ray goes past it and chooses the block behind it. This is most obvious with the new selection box feature, and can cause flickering when picking between the two.

To Reproduce

Clone and compile, find a block nearby and move your cursor to the edges of the blocks.

Expected behavior

The block in-front of the camera should be highlighted, yet it's not. 🤔

Screenshots

https://imgur.com/a/LmxHNIW

Desktop (please complete the following information):

Windows, compiled with VS

Additional context

none

ghost commented 4 years ago

i think i know what's causing the bug. it's because of the raycast taking fixed-size steps, causing the ray to potentially miss the edges of blocks. i scribbled a diagram below to better illustrate this: raycast you probably could just decrease the step size, but it would be a lot more efficient to instead step to the next grid plane on the voxel grid.

Ruixel commented 4 years ago

That's a pretty solid explanation and suggestion. Feel free to assign yourself if you want to fix it, if not I could have a go implementing your suggestion.

ghost commented 4 years ago

oh, yes, please feel free to give it a go yourself. i'm not sure if i can make a reasonably efficient implementation of it myself

Ruixel commented 4 years ago

Bug has been fixed. https://github.com/Hopson97/open-builder/pull/125