-
I’ve been looking into Editable Meshes. How would someone go about creating water that reacts to player movement? Maybe using FindVerticesWithinSphere on roblox documentation. If so, how could I use the array returned to edit nearby vertices?
-
I’m hoping to achieve a simpler version of this water system (https://www.youtube.com/watch?v=6uyPh1OuPl4) on roblox. *I’ll post my progress towards solving this issue. Any suggestions regarding math will help!
1 Like
#Update 1
Used a tutorial to create water waves with Editable Mesh. I watermarked character model as the game is still in testing
- Currently looking into customizing vertices based on player movement with roblox documentation.
Question: How would I add a texture to make the waves more realistic? So far, I made a water texture for testing (8000 x 3000 pixels) , but only the light blue colour appears when added.
2 Likes
Update #2 – Sorry for forgetting to show you my code for review.
I figured out how to capture vertex id’s that the player is interacting with, however, I’m not sure how to change their shape to make it look like the character is moving through it?
Note: Reacting to player movement is at the end of the script.
local mesh = game.Workspace:WaitForChild("WaterPhysics")
local player = game.Players.LocalPlayer
local editableMesh = Instance.new("EditableMesh", mesh)
local width = 100
local height = 100
local offset = 1
local vertexs = {}
--set up editable mesh
for y = 1, height do
local data = {}
for x = 1, width do
local vertPosition = Vector3.new(x-1, 0, y-1) * offset
local vertId = editableMesh:AddVertex(vertPosition)
data[x] = {vertId, vertPosition}
end
vertexs[y] = data
end
for y = 1, height - 1 do
local data = {}
for x = 1, width - 1 do
local v1 = vertexs[y][x][1]
local v2 = vertexs[y+1][x][1]
local v3 = vertexs[y][x+1][1]
local v4 = vertexs[y+1][x+1][1]
editableMesh:AddTriangle(v1,v2,v3)
editableMesh:AddTriangle(v2,v4,v3)
end
end
-- set up waves
game:GetService("RunService").Heartbeat:Connect(function()
for y = 1, height - 1 do
local data = {}
for x = 1, width - 1 do
local vertId = vertexs[y][x][1]
local vertPosition = vertexs[y][x][2]
local currentTime = os.clock()
local newPosition = vertPosition + Vector3.new(0,1,0) * math.noise(
vertPosition.X * 0.1 + currentTime,
vertPosition.Y * 0.1 + currentTime,
vertPosition.Z * 0.1 + currentTime
)
editableMesh:SetPosition(vertId, newPosition)
end
end
--REACTING TO PLAYER MOVEMENT
wait(2)
--get vertices within player distance
local CharacterPos = player.Character.HumanoidRootPart.position
local vertexNear = editableMesh:FindVerticesWithinSphere(CharacterPos, 2)
--print(vertexNear)
if vertexNear == not nil then
for _, vertex in pairs(vertexNear) do
print(vertex)
wait(1)
--edit vertex to react to player movement??
editableMesh:AddVertex(CharacterPos)
end
end
end)
2 Likes