So recently I’ve been experimenting with Roblox’s new Editablemesh and I am trying to recreate the wave produced in this video. However I’ve ran into a few problems, let me list them here
- Collisions don’t work
- Can only be seen on client side not server side
- Weird look to it, ill explain it more later
So starting with the collisions don’t work. Here is a video of my character trying to collide with my editablemesh I created with vertices.
The player can interact with the mesh part just fine, which is the flat blue bottom part, but when it comes to the vertices that have been moved up the player is not able to interact with it. I have CanCollide set to true in my code and I set the CollisionFidelity to PreciseConvexDecomposition. (My code is going to be pasted further down).
Onto the next problem where it can only be seen on the client side and not server side. Someone told me that Roblox hasn’t made it for server side yet, so does anyone know when they will because I am working on a game that requires it to be seen on the server side.
Onto the last and final problem, the weird look to it. I’ll try to explain it the best I can, so basically whenever I use my TweenVertex() function to move one of the vertices forward it looks like this.
It is like connected to the base which is NOT what I want and Im not sure how to fix it because I am brand new to editable meshes. So basically Im trying to make the wave curl/barrel or whatever you call it and It wont work because if i move the vertex forward and down to make the lip of the wave barrel/curl it gets blocked out because its connected. I hope I explained that correctly so whoever is reading this can understand it. But basically in this video they used editable meshes and somehow got the wave to curl/barrel without the vertices doing the weird thing its doing in the photo.
So that was all, thank you so much to whoever read through this entire post to try to help me. I am an experienced developer and I just started using editable meshes like the other day so I hope I’m not bugging anyone too much with all my posts regarding the editable meshes.
Anyways heres my code and it is a server script in workspace for when im testing without my player.
local AssetsService = game:GetService("AssetService")
local RunService = game:GetService("RunService")
local OceanMesh = workspace.WaveFolder:WaitForChild("OceanMesh")
local editable_mesh = AssetsService:CreateEditableMesh({
SkinningEnabled = false
})
local MIN_PART_SIZE = 0.001
function AddQuad(editable_mesh: EditableMesh, vertex_0: number, vertex_1: number, vertex_2: number, vertex_3: number)
local normal_id = editable_mesh:AddNormal()
local face_0 = editable_mesh:AddTriangle(vertex_0, vertex_1, vertex_2)
editable_mesh:SetFaceNormals(face_0, {normal_id, normal_id, normal_id})
local face_1 = editable_mesh:AddTriangle(vertex_0, vertex_2, vertex_3)
editable_mesh:SetFaceNormals(face_1, {normal_id, normal_id, normal_id})
end
function GeneratePlane(editable_mesh: EditableMesh, resolution: number): {{number}}
local vertices: {{number}} = table.create(resolution)
for i = 1, resolution do
local row = table.create(resolution, 0)
vertices[i] = row
end
local size_step = 2 / resolution
for x_index = 1, resolution - 1 do
local x_start = ((x_index - 1) * size_step) - 1
local x_end = (x_index * size_step) - 1
if(x_index == 1) then
local vertex_0 = editable_mesh:AddVertex(Vector3.new(x_start, MIN_PART_SIZE, -1))
vertices[x_index][1] = vertex_0
end
local vertex_2 = editable_mesh:AddVertex(Vector3.new(x_end, 0, -1))
vertices[x_index + 1][1] = vertex_2
for z_index = 1, resolution - 1 do
local z_start = ((z_index - 1) * size_step) - 1
local z_end = (z_index * size_step) - 1
local vertex_0 = vertices[x_index][z_index]
local vertex_1
if(x_index == 1) then
vertex_1 = editable_mesh:AddVertex(Vector3.new(x_start, 0, z_end))
vertices[x_index][z_index + 1] = vertex_1
else
vertex_1 = vertices[x_index][z_index + 1]
end
local vertex_2 = editable_mesh:AddVertex(Vector3.new(x_end, 0, z_end))
local vertex_3 = vertices[x_index + 1][z_index]
vertices[x_index + 1][z_index + 1] = vertex_2
AddQuad(editable_mesh, vertex_0, vertex_1, vertex_2, vertex_3)
end
end
return vertices
end
local resolution = 100
local vertices = GeneratePlane(editable_mesh, resolution)
local mesh_part = AssetsService:CreateMeshPartAsync(Content.fromObject(editable_mesh), {CollisionFidelity = Enum.CollisionFidelity.PreciseConvexDecomposition})
mesh_part.CanCollide = true
OceanMesh:ApplyMesh(mesh_part)
function TweenServiceVertex(editable_mesh, vertex_id, target_position, duration)
local start_position = editable_mesh:GetPosition(vertex_id)
local elapsed = 0
local connection
connection = RunService.Heartbeat:Connect(function(dt)
elapsed += dt
local alpha = math.clamp(elapsed / duration, 0, 1)
local new_position = start_position:Lerp(target_position, alpha)
editable_mesh:SetPosition(vertex_id, new_position)
if alpha >= 1 then
connection:Disconnect()
end
end)
end
function TweenRow(xVal, zVal, way, amount, tweentime)
for x = xVal, resolution do
local vertex_id = vertices[x][zVal]
if vertex_id then
if way == "Up" then
local start_position = editable_mesh:GetPosition(vertex_id)
local up_position = start_position + Vector3.new(0, amount, 0)
TweenServiceVertex(editable_mesh, vertex_id, up_position, tweentime)
elseif way == "Down" then
local start_position = editable_mesh:GetPosition(vertex_id)
local down_position = start_position + Vector3.new(0, -amount, 0)
TweenServiceVertex(editable_mesh, vertex_id, down_position, tweentime)
elseif way == "Forward" then
local start_position = editable_mesh:GetPosition(vertex_id)
local forward_position = start_position + Vector3.new(0, 0, amount)
TweenServiceVertex(editable_mesh, vertex_id, forward_position, tweentime)
elseif way == "Backward" then
local start_position = editable_mesh:GetPosition(vertex_id)
local backward_position = start_position + Vector3.new(0, 0, -amount)
TweenServiceVertex(editable_mesh, vertex_id, backward_position, tweentime)
end
end
end
task.wait(0.1)
end
function TweenVertex(xVal, zVal, way, amount, tweentime)
local vertex_id = vertices[xVal][zVal]
if vertex_id then
if way == "Up" then
local start_position = editable_mesh:GetPosition(vertex_id)
local up_position = start_position + Vector3.new(0, amount, 0)
TweenServiceVertex(editable_mesh, vertex_id, up_position, tweentime)
elseif way == "Down" then
local start_position = editable_mesh:GetPosition(vertex_id)
local down_position = start_position + Vector3.new(0, -amount, 0)
TweenServiceVertex(editable_mesh, vertex_id, down_position, tweentime)
elseif way == "Forward" then
local start_position = editable_mesh:GetPosition(vertex_id)
local forward_position = start_position + Vector3.new(0, 0, amount)
TweenServiceVertex(editable_mesh, vertex_id, forward_position, tweentime)
elseif way == "Backward" then
local start_position = editable_mesh:GetPosition(vertex_id)
local backward_position = start_position + Vector3.new(0, 0, -amount)
TweenServiceVertex(editable_mesh, vertex_id, backward_position, tweentime)
end
end
task.wait(0.1)
end
coroutine.wrap(function()
-- Wave build up
local PeakHeight = 20
local xVal = 30
local zVal = 10
repeat
task.wait()
TweenVertex(xVal, zVal, "Up", PeakHeight, 0.4)
xVal -= 1
PeakHeight -= 1
until PeakHeight == 0
local PeakHeight2 = 19
local xVal2 = 31
local zVal2 = 10
repeat
task.wait()
TweenVertex(xVal2, zVal2, "Up", PeakHeight2, 0.4)
xVal2 += 1
PeakHeight2 -= 1
until PeakHeight2 == 0
-- Barrel
TweenVertex(30, 10, "Forward", 0.2, 0.4)
end)()
One last thing, I get this error in the output that says this : “AssetService:CreateEditableMesh: Unknown option parameter: SkinningEnabled” It doesn’t affect much but it would be nice to know a little more about it thanks! Also I am NOT asking for someone to fix my code but to rather point me in the right direction and then Im sure I’ll be able to figure it out from there.