I’m trying to make a part, or an object having 1 surface fitting exactly the terrain. I’ve tried with orientation of the mouse.Target,
However I knew it wouldn’t work correctly mostly because every triangle is oriented to fit the other triangles, so none of the triangles have a logic orientation.
Is there a way to just make two surfaces fit eachothers?
The way I place objects:
return CFrame.new(math.floor(m.Hit.X/2)*2, m.Hit.Y+p.Size.Y/2, math.floor(m.Hit.Z/2)*2)*CFrame.Angles(find angle x, rot, find angle z); --rot = rotation chosen by player by pressing on r```
You could try doing a raycast from Mouse.UnitRay and using the returned surface normal to rotate your object’s CFrame. I forget which CFrame function it is to rotate using a vector, but I’ll look it up and edit this post when I find it.
Edit: maybe you could try constructing a CFrame by using the normal as upVector, calculating rightVector and backVector and plugging those in to CFrame.fromMatrix()? I’m on phone so it’s hard to show some working code
local mouse = game:GetService "Players".LocalPlayer
local targetFilter = mouse.TargetFilter
local _, hit, normal = workspace:FindPartOnRay(
Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 5000),
targetFilter)
local cframe = CFrame.new(hit, hit + normal)
This is actually simpler than I thought it would be
There used to be an article on the wiki about the cross product but that didn’t seem to make the migration. Regardless here’s an updated version of that article which has an example of the cross product in use to rotate an object to the surface the mouse is pointed at.