So, i’m attempting to make a drawing system using parts, and i need parts to automatically rotate themselves to be flat on the canvas.
I have no clue how to do this, so any help would be nice.
Here is my code, which half works, but not really.
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Character, workspace:WaitForChild('Paint')}
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
local RayOrigin = Camera.CFrame.Position
local RayDirection = Mouse.Hit.Position * PaintRange
local Result = workspace:Raycast(RayOrigin, RayDirection, RayParams)
if Result and Result.Normal and (Result.Position - LastPaintPosition).Magnitude >= PaintSize then
local NewPart = script:WaitForChild('Paint'):Clone()
NewPart.Color = Currect_Color.Value
NewPart.Size = Vector3.new(PaintSize, PaintSize, 0.001)
-- Both position and rotation are wrong
NewPart.CFrame = CFrame.new(Result.Position) * Mouse.Hit.Rotation
NewPart.Parent = workspace.Paint
end
This is the part i am attempting to rotate, and i want it to appear flat on any rotated surface.
That wouldnt exactly work if i add unions as surfaces you can paint on though, plus it would be a pain to make sure that all surfaces that can be painted on are facing the correct way.
Thanks, i did know that the Normal was probably needed, so i had the check there for it.
The painting position is still offset from the mouse a lot, but at least rotation works now.
Edit: Changed origin from root part to camera and it fixed the offset