I have tried shapecasting a capsule onto a pyramid (both meshparts), and found out that the point from the result is not perfectly on surface but either inside or outside by a small distance. If you then apply cast direction * result.Distance, you end up with the part A penetrating the part B. At this moment, this issue halts the development of my game. I need this problem to be solved as soon as possible.
meshes i have tested with:
11643615120
7825007598
7280851812
15440301553
482906818
here’s simple code example:
local a: MeshPart = script.a
local b: MeshPart = script.b
game:GetService(“RunService”).Heartbeat:Connect(function(dt)
local dir = (b.Position - a.Position)
local result = workspace:Shapecast(a, dir)
local originCF = a.CFrame
if result then
a.CFrame = CFrame.new(originCF.Position + dir.Unit * result.Distance)
assert(#workspace:GetPartsInPart(a) == 0, “part is inside the other.”)
a.CFrame = originCF
end
end)