Trouble with terrain ore detection

  1. Hello, I’m 4Slu and I’m working on a survival game with almost infinite (until the null zone) terrain generation. There’s currently ores and caves and the ores are made out of coloured terrain chunks. I’m trying to figure out how to detect the material and give the player the ore after hitting it.

  2. The issue is I have no idea how to detect terrain infront of the player.

  3. I’ve tried to use detect floor material and fill the area infront with air but that requires the player to stand ontop and is confusing for new players.

If you find anything your comment would be greatly appreciated, have a good day and thanks for reading.

Just to clarify, you’re using actual Roblox-generated terrain for this?

1 Like

I’m not quite sure how you’re defining ‘in front of’ in mathematical terms, but the 4th value returned by :FindPartOnRay() is material, and this works with terrain materials too. So you can continually raycast in front of the player to find the material.

5 Likes

Yes. I’m using various materials coloured to look like ores.

1 Like

it detects specific materials, correct?

Yep, it will return one of these: Material | Documentation - Roblox Creator Hub

2 Likes