How can I detect what terrain material a part is touching?

I really have no previous experience in this area, but I’m trying to make a script that does this:

-Part is touched
-Part recognizes what terrain material touched it
-Part names itself that terrain material

It’s pretty simple, but it will save me a ton of time because I’ll make a ton of parts fall and paste grass meshes into each of the grass parts, light grass meshes into each of the sand, etc.

There might be a more practical way to do this but here is my idea.

After the touched event
Make several rays fired in a bunch of directions outwards from the part.
A ray can return the position it hit and the material of what it hit, works for terrain materials too. So just compare the distance of the ray hitpoints and find the closest one that makes sense to fire the touched event. To wrap it all up just set the name to the tostring(material) returned value.

5 Likes

Haha, I don’t know about you, but I think it works pretty good. :stuck_out_tongue:

Maybe one day somebody will make a plugin :joy:

3 Likes

oof I demand 60% of all profits off the plugin

7 Likes

i claim

1 Like

The easier method is to use the position of the part as the origin, and the velocity of the part as the direction. This usually guarentees an accurate description of what object got hit.

5 Likes