https://i.imgur.com/QxThulG.jpg
I'm using cross product to get the angle of a part side relative to the world. This allows me to rotate a second object to match the angle of a first object even if the first object isn't a cube.
local ray = Ray.new(game.Workspace.Camera.CoordinateFrame.p, (player:GetMouse().Hit.p - game.Workspace.Camera.CoordinateFrame.p).unit * 50) local part,position, normal = game.Workspace:FindPartOnRay(ray,nil,false,true) Targetcross = Vector3.new(1, 0, 0):Cross(normal) Targetangle = math.asin(Targetcross.magnitude) print("Target angle=", Targetangle) print("degrees..", math.deg(Targetangle))
If object 1 has a side (not CFrame side) angled at 86 degrees on the Y axis relative to the world Z axis, (not relative to the CFrame), I can change the CFrame.Angle of object 2 to match object 1, and this works as expected. Using CFrame.p to disregard any current rotation of object 2, the "mover".
Mover.CFrame = CFrame.new( Mover.CFrame.p) * CFrame.Angles(0, Targetangle, 0 )
But if object 2 isn't a cube or has arbitrary angled sides, Then only it's frame matches object 1's side angle. For example, an object with 30 sides has a side angle of 86 degrees. We can rotate a second part, a cube, so that it is also 86 degrees relative to the world. But if the second object is a triangle, then setting it's CFrame to 86 will not align it's short sides to the cube, only its frame.
This means I need to rotate the triangle to the desired 86 degrees minus the angle of the triangle face and it's frame. I don't know how to get that. If I used cross product to get the angle of the triangle side, then I still can't use it to subtract from the CFrame rotation because the angle I get would be relative to the world Z axis and not the CFrame. So considering that last sentence, how could I get the angle of the triangles face relative to it's CFrame?