Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to set the upwards orientation of a part based on a surface normal of ground below?

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

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.