I am creating a game which involves mining at it’s core. Caves are procedurally generated and valuable ores are generated inside of the terrain. What I want to do is develop an antiexploit/anticheat system so it is not possible to xray the location of ores, preventing unfair advantage by knowing where all of the rare ores are located.
What I am trying to figure out is what would be the most performant solution since there are over 5000 ores/models per map. I am not worried about the players knowing where the ores are located but rather hiding what they actually are.
What first came to mind was adding a part to each ore which goes around it and when a player is touching the part would trigger a script to read what ore is actually there from a table and then render it’s model. However I am worried that connecting over 5000 events is not a good idea at all.
Another solution which comes to mind for me is tracking all players coordinates and periodically(every second for example) checking which ores are in a Region3 around the player and then displaying their models.
There are no code examples because I am simply trying to figure out what would be the most performant method to do this and not how to implement it.
Is your game block based or similar? If so, a good solution would be storing location information on the server only.
Have the server only parent/show ores with at least 1 face uncovered. When players mine ores check if adjacent ones will end up with any of their faces uncovered and if so render them in.
Would be a good idea if my game was block based but sadly it is not. It is using terrain for the caves themselves and then ores are placed as parts inside of the terrain. They are always hidden inside of the terrain since no valuable ores actually spawn inside of the caves.
But you just gave me an idea, when a player mines I already destroy terrain in a Region3, so what if I checked if there were any ores nearby when a player mined and then then rendered them.
You should use a separate larger Region3 for the ores. Terrain works by having an occupancy value which ranges from 0-1, while :FindPartsInRegion3 is not very accurate. This means that some ores might remain invisible even if they are uncovered, unless you specify a small threshold.
Ah yes, you are right. This definitely seems like the most logical solution to me, performing checks whenever a player has mined instead of performing them constantly and checking if there are any ores in the surrounding area.