Hello! yeah as the title says i can’t make a part face the same direction as the wall surface, i know this can be a stupid thing but i dont really worked with Normals, here is the code:
function RaycastNote(notePart)
local rayP = RaycastParams.new()
rayP.FilterDescendantsInstances = {notePart}
RayRun = RunService.Stepped:Connect(function()
local rayData = Workspace:Raycast(mouse.Origin.Position, mouse.Hit.Position * 20, rayP)
if rayData then
local targetPos = rayData.Position + rayData.Normal
local lookAtRotation = CFrame.lookAt(notePart.Position, targetPos)
notePart.CFrame = lookAtRotation
end
end)
end
This post was quite confusing, but what I understood was that you wanted to have a part face the same direction as a wall that’s hit by a raycast. To do this, set the part’s LookVector to the Normal of the Ray.
If my understanding of your post was incorrect, please try to clarify exactly what you want to happen.
You’re not allowed to directly assign Part.CFrame.LookVector. Roblox only allows you to directly write to Part.CFrame, meaning you’d have to calculate a CFrame with the correct lookvector. One method I use to do this is setting the part’s CFrame to CFrame.new(part.Position,part.Position+Normal).
You also may just be able to set part.Orientation = Normal instead of constructing a new CFrame, so I guess try that first if you want. Not totally sure it works though.
After opening studio I realized that note.CFrame = CFrame.new(ray.Position,ray.Position+ray.Normal) should be used to set both the position and the LookVector at the same time. Also, try setting up your raycast like this, where camera is equal to workspace.CurrentCamera:
local unitRay = camera:ViewportPointToRay(uis:GetMouseLocation().X,uis:GetMouseLocation().Y)
local ray = workspace:Raycast(unitRay.Origin,unitRay.Direction*20,params)