So what I'm trying to do is set the orientation of a part relative to the ground or part beneath. Currently I'm using a ray downwards from the part and FindPartOnRay to get the normal of the surface below. I have no problem positioning the object near the ground but when I try to orient it I'm failing miserably. The code below works only for 1 direction so I'm thinking that the + 90 degrees there is right only in the context of my current direction.
local function setSledOrientationToSurfaceNormal(surfaceNormal) surfaceNormal.X = math.abs(surfaceNormal.X) surfaceNormal.Y = math.abs(surfaceNormal.Y) surfaceNormal.Z = math.abs(surfaceNormal.Z) local cframe = sled.CFrame sled.CFrame = CFrame.new(cframe.Position, cframe.Position + surfaceNormal) sled.Orientation = Vector3.new(sled.Orientation.X + 90, sled.Orientation.Y, sled.Orientation.Z) --sled.Orientation = Vector3.new(sled.Orientation.X, sled.Orientation.Y, sled.Orientation.Z) end
If it is unanchor you need to do CFrame's so like Example
sled.Weld.C0 = CFrame.fromEulerAnglesXYZ(math.rad(0),math.rad(0),math.rad(0))
(This is Example)