Hello everyone, so I have this placement script that moves a painting on the wall where the mouse is pointing. This is some of the code for it:
local currentRotation = model.PrimaryPart.Orientation.Z -- Changes the rotation to its relative current item's rotation
model:SetPrimaryPartCFrame((CFrame.new(math.round(mouse.Hit.X), math.round(mouse.Hit.Y), math.round(mouse.Hit.Z + 0.6)) * (CFrame.Angles(0,math.rad(180),math.rad(currentRotation)))))
So this works as intended, the painting goes to where the mouse is pointing on the wall but I would like for it to not clip past the wall or in other ways stay completely within the boundaries of the wall and not have the other half go past the wall. Do you know how I can accomplish this? Any formulas? Thanks!
Mouse.Hit is actually pretty bad imo
Instead, what I would do is to get the Vector2 position of the mouse on the screen and then convert it into a ray using camera:ScreenPointToRay()
Using the ray’s information, perform a raycast
Now to finally address the issue of clipping, you could put an attachment inside the painting where u want the painting to be attached to the wall
And when pivoting the model to the CFrame, consider the attachment’s objectspace CFrame