How can I fit a mesh into 4 Vector3 points?

Hello, I am working on a script that allows me to paint objects onto any part that the player hits. So I am gonna get these 4 points with rays, then I wanna fit this mesh I have made between them, any ideas on how to do it?

Here is an example of my 4 points:

Here is the paint mesh that I am trying to scale/fit between the 4 Vector3 points.
paint

Any help is appreciated, thanks.

Linear interpolation would work to great get where the mesh goes.

local function lerp(v1,v2,alpha)
    return v1:Lerp(v2,alpha)
end
local function lerpbetweenfourpoints(v1,v2,v3,v4)
    local lerp1 = lerp(v1,v2,0.5)
    local lerp2 = lerp(v3,v4,0.5)
    local final = lerp(lerp1,lerp2,0.5)
    return final,lerp1,lerp2
end
-- moving the meshpart
local newmesh = MeshPart:Clone() -- just use the reference to the meshpart
local position,l1,l2 = lerpbetweenfourpoints(part1.Position,part2.Position,part3.Position,part4.Position) -- define the parts beforehand
newmesh.Position = position
-- resize and change rotations as necessary
newmesh.Parent = workspace.Terrain
3 Likes

Thank you, I will try this out.