Hey there!
How can I detect when a part touches terrain? I’m using this for a helicopter crash script, but I’m not sure how to do this. Any help is appreciated!
I don’t think there’s something like “.Touched” for the terrain.
The only thing that comes to my mind is making an invisible part over the terrain and then using the “.Touched” event.
Hope this helped, have a nice day!
I see how that would work, however it would be time consuming and overall, not the best option to go with, considering my current terrain:
I appreciate the help, though.
if Hit:IsADescendantOf(workspace) and not Hit:IsA("BasePart") then
--do stuff
end
I haven’t tested it yet, but doesn’t BasePart:GetTouchingParts() check for terrain? I remember reading that somewhere.
I thought .Touched did work for Terrain?
I’d hope so, since GetTouchingParts() is probably not performant to be called too many times in a row.
If .Touched doesn’t work, then multiple Raycasting with a Whitelist containing only the Terrain should work. Since you’d only need to cast a handful of rays in a few directions from the center of your helicopter AND your rays only need to be ever so slightly longer than the helicopter’s distance from its center, those short rays won’t be resource-consuming, so that’s probably the most performant way to go.
Its basically 100% more accurate thanks so much
Refined Version of your script
local workspace = game:GetService("Workspace")
local function isTouchingGrass(part)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {workspace.Terrain}
params.FilterType = Enum.RaycastFilterType.Include
local ray = workspace:Raycast(part.Position, Vector3.new(0,-10,0) * 10, params)
if ray then
print(ray.Material)
if ray.Material == Enum.Material.Grass or ray.Material == Enum.Material.LeafyGrass then
return true
else
return false
end
else
return false
end
end
for _, instance in pairs(workspace:GetDescendants()) do
if instance:IsA("Part") and isTouchingGrass(instance) then
script.Highlight:Clone().Parent = instance
end
end