Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do you detect contact with Terrain?

Asked by
nobo404 17
8 years ago

I have a large game that features the Smooth Terrain feature. However, what I would like to do is light a player on fire when they touch Cracked Lava terrain, as described in the following pseudocode:

while true do
    for plr in game.Players do
        if plr is touching CrackedLava terrain -- what I need help with
            (set plr on fire) -- I know how to do this and do not need help
        end
    end
    wait(0.1)
end

Basically, that is what I need to do. However, it probably will not need the loop, as that could cause lag. Here is another method I came up with that probably won't work, but I can't try it, as I don't actually know how to do some things.

let terrain = game.Terrain

for (voxel of type "CrackedLava") in terrain do -- don't know if something like this is possible
    (surround terrain with part named "LavaPart") -- don't know how to do this either
end

for (part named "LavaPart") -- know how to do this
    (insert script from ServerScriptService into part) -- know how to do this
end

That might work, but still would have lag on older machines, most likely even more than the initial method of covering it in bricks. It would also need to have a way to gather all the Smooth Terrain voxels. However, it does solve two initial problems, and an answer like this would be acceptable. (I really just want to not spend a really long time covering up my world with parts.)

So, can anyone please rewrite one of these examples into actual ROBLOX Lua or come up with a completely different method that works? (Please explain any code, as I am trying to learn some stuff by making ROBLOX games)

0
http://wiki.roblox.com/index.php?title=API:Class/Terrain/ReadVoxels , never used it myself, but it looks like it uses Region3 and returns the material. Use that + a touched event and you should be able to do what you need to. Pyrondon 2089 — 8y
0
Can you please explain that in an Answer Pyrondon? nobo404 17 — 8y

2 answers

Log in to vote
0
Answered by
Nidoxs 190
8 years ago

I know this is probably not what you wanted but using bricks on top of the desired terrain will still work, just create the same script that checks if the player is touching the brick that is just above the terrain. (Set them to 1 transparency and false cancollide)

0
You can use a .Touched event and detect whether the Part being touched :IsA("Terrain"). You can probably check what the material of the chunk of Terrain being touched is, but I don't know. UniversalDreams 205 — 8y
0
Can you please explain that in an Answer UniversalDreams? I don't know how to apply Touched events to non-parts. nobo404 17 — 8y
0
doctorbenny2011, reading your answer 21 days after it was posted gave me a pretty good idea. Looking back at my terrain generation results, it's pretty smooth, so I could use a few EXTREMELY large parts to cover the lava until something better comes along. nobo404 17 — 8y
0
Your welcome, I used this system once and it also worked as smooth as smooth terrain! :3 Nidoxs 190 — 8y
Ad
Log in to vote
0
Answered by 6 years ago

I know a way you could check the material the humanoid is standing on, but if the humaniod's lying down, it won't work.The following script will make the players take damage if they're standing on lava(put it in the starterpack): --Begin-- local Humanoid = game.Players.LocalPlayer.Character.Humanoid while true do local Material = Humanoid.FloorMaterial if Material == Enum.Material.CrackedLava then Humanoid:TakeDamage(20) end wait(.1) end --End-- Even though this would lead to a swift death, I hope you find it useful.

0
How do add a script in an answer? Thelegendofbrio13 0 — 6y
0
simple Deinonychusaurus 21 — 4y

Answer this question