I am currently making a placement tool. There is no placement grid. Here’s the type of thing it should do:
However, when the tool encounters slopes it messes up.
Notice how it clips into the part. In addition, rotating the object also messes it all up.
Here’s the current code for it:
adjustedCFrame = CFrame.new(raycastResult.Position)
adjustedCFrame = adjustedCFrame:ToWorldSpace(CFrame.Angles(math.rad(raycastResult.Instance.rotation.x), math.rad(raycastResult.Instance.rotation.y), math.rad(raycastResult.Instance.rotation.z)))
adjustedCFrame = adjustedCFrame:ToWorldSpace(rotatedCFrame) -- the user can rotate the object. this code applies that rotation.
adjustedCFrame = adjustedCFrame:ToWorldSpace(CFrame.new((clonedPart[1].PrimaryPart.Size.x / 2) * raycastResult.Normal.x, (clonedPart[1].PrimaryPart.Size.y / 2) * raycastResult.Normal.y, (clonedPart[1].PrimaryPart.Size.z / 2) * raycastResult.Normal.z))
It’s quite messy so I’ll explain what it is currently doing. First, it creates a cframe from the mouse’s position in the world. Then it relatively rotates the object so that it’s rotation matches that of the object the mouse is pointing to. Next, it rotates the object corresponding to how the user tells it to. Finally, it offsets the object so that (hopefully) it isn’t clipping into any other parts.
I’ve stared at the code so long I don’t know what it means anymore to be honest. Please help me from my CFrame hell.