Best way to check is a raycast if within a voxel

Hello! its me again. i am wondering what would be the best way for me to detect if a raycast is within a voxel? a great example of what i am trying to achieve is the block breaking in Minecraft

1 Like

Index the “Material” key/field of the returned “RaycastResult” value. If the casted ray hit a BasePart the value assigned to this key/field would describe the BasePart’s material (what material enumeration is assigned to its “Material” property). Alternatively, if the casted ray hit a Terrain cell the value assigned to the key/field would describe the Terrain cell’s material and is largely dependent/reliant on the Terrain itself.

1 Like

No not what I mean I already know how the raycast API works. That won’t be able to work since I am planning of using greedy mesh to optimize it

1 Like

A few questions I have:

  1. Are you using custom terrain, like blocks? Or is it Roblox terrain.
  2. Did you already create the terrain generation script?
1 Like

It’s gonna use parts, and no I didn’t start working on the terrain script yet since i want to figure out this first

I think you’ll have to create the terrain generation first before solving this issue. Once you’ve created a terrain generation script, you will be able to determine what block is in a specific ‘position.’

After raycasting (and this is after you’ve implemented the greedy mesh system) you will get RaycastResult.Position and RaycastResult.Instance. You can use the Instance part to determine what greedy mesh section you got and you can use the Position part to determine what block is most likely to be the block they hit.

Use all 3 things I’ve talked about and you’ll develop a failproof way of determining what block the player hit.

1 Like

Damn thanks man this might work