How can i get the correct orientation values of based off of a normal vector, as in being able to calculate the correct x y and z orientation to set to when a part is at an angle
like this;
an example of part being on a slant
I don’t remember what orientation is relative to but I think it’s just the worldspace vectors. So just go through every axis vector and get their angle (remember that if dot product is equivalent to the product of the magnitudes times cos(k) then if they are unit vectors it is just what equals the cos(k) and itself in other words it is the inverse cosine of the dot product of them) remember to put a negative sign in the orientation or it will make it wrong
You can use CFrame.lookAt for making a part face the direction of the ray result, then apply respective offsets if the part is flipped, tilted, and so on.
local cframe = CFrame.lookAt(rayresult.Position, rayresult.Position + rayresult.Normal)
cframe *= CFrame.fromOrientation(math.pi/2, 0, 0) -- example: flip by 90 degs
cframe *= CFrame.new(0, 0, -size.Z/2) -- example: move forwards by half its z size (to not clip in the surface)
You might have to experiment a little, but this is really all you need.
If you insist on getting the orientation, which you don’t need, you can call :ToOrientation on the CFrame to get the orientational x, y, and z value then convert them to degrees like so:
local cframe = CFrame.lookAt(rayresult.Position, rayresult.Position + rayresult.Normal)
local radx, rady, radz = cframe:ToOrientation()
local orientation = Vector3.new(math.deg(radx), math.deg(rady), math.deg(radz))
i need the orientation to be able to put into a balance controller im trying to make that uses a pid and i want to be able to make the the orientation the setpoint on the pid and use the humanoidrootpart orientation as the processvalue
also i was under the presumption that the cframe stuff would make it be able to move around flat in context to the surface but it appears that it only does that one direction like this
what im saying is instead of doing the correct orientation it is trying to do positive 15 degrees instead of the proper -15
so it ends up something like this
Ah, that’s because of how you apply the rotation offset. You’d want to apply the rotation to the CFrame before it’s converted to a Vector3 orientation.