Changing The Center of EditableMesh

Hey all,

I have a simple script setup where every .1 seconds, the script grabs the position of a part and then finds the Vertex on an EditableMesh closest to that part, then moves a dot to the position of the Vertex to visualize it. Shown below.

local AssetService = game:GetService("AssetService")
local editable_mesh = AssetService:CreateEditableMeshAsync(script.Parent.MeshContent, {FixedSize = false})
local mesh_part = AssetService:CreateMeshPartAsync(Content.fromObject(editable_mesh))
mesh_part.Position = script.Parent.Position
mesh_part.Size = script.Parent.Size
script.Parent:ApplyMesh(mesh_part)

editable_mesh:Triangulate()

local function CreatePart()
	local Part = Instance.new("Part")
	Part.Size = Vector3.new(.4,.4,.4)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Parent = workspace
	Part.Color = Color3.fromRGB(255, 0, 0)
	return Part
end

local RefPart = CreatePart()

while true do
	task.wait(.1)
	
	local Vertex = editable_mesh:FindClosestVertex(workspace.TargetBrick.Position)
	local LocalPosition = editable_mesh:GetPosition(Vertex)
	local Position = script.Parent.CFrame:PointToWorldSpace(LocalPosition * script.Parent.Size / script.Parent.MeshSize)

	RefPart.Position = Position
end

https://gyazo.com/aa21b68d543b649d7dc6618cf42476f6

However, whenever the MeshPart’s position is away from the center of the map (0,0,0) the “center” of the EditableMesh does not along with it, making it inaccurate, shown below.

https://gyazo.com/123486f65e7717fd881fb035d938fec2

Is there a way to move the center of an EditableMesh to a different position? Or “impose” the verticies to a different position instead?

Try use the local position of the TargetBrick instead of world space location when you call FindClosestVertex

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