EditableMesh has no collisions

I have some code for doing a marching cubes mesh

local MeshPart = Instance.new("MeshPart", workspace);
local EditableMesh = Instance.new("EditableMesh");

MeshPart.Position = Vector3.new(0, 0, 0);
MeshPart.Size = Vector3.new(1, 1, 1);

MeshPart.Anchored = true;
MeshPart.CanCollide = true;

EditableMesh.Parent = MeshPart;

local Resolution = Vector3.new(32, 32, 32);
local Map = {
	densities = {}
};

local s = 5
local h = 32

for x = 1, Resolution.X do
	for y = 1, Resolution.Y do
		for z = 1, Resolution.Z do
			local index = x + (y - 1) * Resolution.X + (z - 1) * Resolution.X * Resolution.Y
			
			local height = (x + z) / (Resolution.X + Resolution.Z) * Resolution.Y;
			
			if y == height then
				Map.densities[index] = 0.5
			elseif y > height then
				Map.densities[index] = 0
			else
				Map.densities[index] = 1
			end
		end
	end
end

local ReplicatedStorage = game:GetService("ReplicatedStorage");

local MakeMesh = require(ReplicatedStorage.MakeMesh)

local Mesh = MakeMesh(Map, Resolution)

local verticesAdded = 0
for _, triangle in ipairs(Mesh) do
	EditableMesh:AddVertex(triangle.a);
	EditableMesh:AddVertex(triangle.b);
	EditableMesh:AddVertex(triangle.c);

	EditableMesh:AddTriangle(verticesAdded + 1, verticesAdded + 2, verticesAdded + 3)
	verticesAdded += 3
end

However, the mesh has no collisions, even with CanCollide set to true:

I don’t see any function (or way) to enable collisions

2 Likes

Editable meshes don’t support collision geometry yet, you’ll have to wait until the CreateMeshPartAsync and ApplyMesh functions are available

One alternative you can try is generating 2 invisible wedges at each triangle, this article by EgoMoose explains it pretty well and includes the code

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.