Hi! Suppose a ray has been casted towards a sphere or any other shape, this gives you useful information, one of them being the surface normal which is calculated from the intersection point of the ray. I intend to use the surface normal in order to orient an object onto a sphere or other shape's planes.
This wiki document demostrates this well, and it's the base method I have been relying on.
However, this method stops functioning properly once the oriented object reaches the bottom-half of a sphere. Workarounds were attempted with narrow success.
I managed to get around this by getting the angle between the up vector and the surface normal with the dot product.
local Cross = Vector3.new(0, 1, 0):Cross(SurfaceNormal) local Angle = Vector3.new(0, 1, 0):Dot(SurfaceNormal) Part.CFrame = CFrame.new(Mouse.Hit.p + SurfaceNormal * Part.Size.Y / 2) * CFrame.fromAxisAngle(Cross.Magnitude == 0 and Vector3.new(1, 0, 0) or Cross.Unit, Angle)
But then new problem arrives: The object's Y axis begins to abnormally spin whenever it's nearby the bottom-center of the sphere. I can't seem to figure this one out. Here's a demostration.
Any advice is appreciated.