-
What do you want to achieve? Keep it simple and clear!
I want to detect if a part is inside of terrain -
What is the issue? Include screenshots / videos if possible!
Im not sure how to do it. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried YT and DevForum.
Not sure exactly what the part is or what the terrain looks like, but if you have flat terrain you can determine it’s Y value and get the position of the part and compare it if it’s less than (<) terrain Y value.
If this is not what you’re looking for, could you elaborate more about the part and what you’re trying to achieve?
Its just a normal part and my terrain is not flat, so how could I achieve my goal?
You could maybe use a raycast? Do you want tk onow if its fully covered or just partially? If its partislly, use a shapecast.
I’m using raycast rn (im making a placement system) so how could I detect if my viewmodel is inside terrain?
You can use Terrain:ReadVoxels().
It’s pretty complicated to learn it, but it can super beneficial once you learn it.
Raycasts also work.
You could try detecting it using the terrain size, something like this:
local terrain = game.Workspace.Terrain
local terrainSize = terrain.Size
local part = game.Workspace.PartToCheck
local partPosition = part.Position
local minX = -terrainSize.X / 2
local minY = 0
local minZ = -terrainSize.Z / 2
local maxX = terrainSize.X / 2
local maxY = terrainSize.Y
local maxZ = terrainSize.Z / 2
if (partPosition.X >= minX and partPosition.X <= maxX) and
(partPosition.Y >= minY and partPosition.Y <= maxY) and
(partPosition.Z >= minZ and partPosition.Z <= maxZ) then
-- The part is inside the terrain
print("The part is inside the terrain.")
else
-- The part is outside the terrain
print("The part is outside the terrain.")
end
maybe you could also detect with collision, if it is colliding with terrain and take actions before hand.
I already looked at that and it didn’t help me