So I made a really big island map using Roblox terrain, and I’m trying to make terrain objects (rocks, trees, etc.) generate in random spots when a player joins.
The problem I’ve run into is that sometimes the objects load perfectly, but they’re on top of/below water, and it looks really weird; like somebody would think it’s a bug or something.
I think the ideal solution to my problem would be to find out if the object is touching water or not, and if it is, then remove it. But I’ve been faced with another dilemma: I can’t find a way to detect if the object water terrain or not, since touched event doesn’t work with terrain.
The only way I’ve found out so far is to place invisible parts in the water regions and detect collisions with those parts, but this really isn’t a perfect solution since I’ll need to place a LOT of parts to accomplish this, and also, because it’s inconvenient to place parts in such a way that it fits into every nook and cranny of your rivers/lakes.
I would appreciate any suggestions on what I should do.
You mean CFrame.Magnitude??
But I’m trying to find a way to detect if the part touches water or not, and isn’t Magnitude used for finding a distance of one part from another part?
TY.
I don’t really know much about raycasting and that’s probably why I didn’t think of it. I’m going to start finding out more about it to see if it helps.
I’m pretty sure Region3 won’t work. Even though I haven’t tried it, I’ve seen a post saying that FindPartsInRegion3 () is very much like touched events when it comes to detecting collisions.
The only thing left for me to try out is raycasting probably.
It depends on what kind of part, if it is a floating part, you can just use RayCast to get RayCastResult, which has a material variable showing whether it is Water or not.
Another situation is that if the part will sink into the river bed, you can use Terrain Edit to paint the river bed to a special material which other parts of the world won’t use, in my example, paint it to Mud material. Since the sinking part will touch the river bed, it won’t detect the water material in this case, but it will detect Mud material. By this way, you will know if it is in water.
By the way, touched event can be an option. like this.
workspace.Terrain.Touched:Connect(function(hitPart)
– todo
end)