Detailed CFrame

Just to help the beginner community better understand the subdivision of CFrame and also avoid confusion with the floating-point inaccuracies (as per this post), here is a small snippet:

 -- rounds numbers with specified decimal places (ex: round(1.2345, 3) == 1.235)
function round(number, digits)
	local num = number * 10 ^ digits
	num = num>=0 and math.floor(num+0.5) or math.ceil(num-0.5) -- round number (including negative numbers)
	return num / (10 ^ digits)
end

function CFrameDetailed(cf)
	print('CFrame:\t', cf, '\r')
	print('Position:\t', round(cf.Position.x, 2), '\t', round(cf.Position.y, 2), '\t', round(cf.Position.z, 2)) 
	print('RightVector:\t', round(cf.RightVector.x, 2), '\t', round(cf.RightVector.y, 2), '\t', round(cf.RightVector.z, 2))
	print('UpVector:\t', round(cf.UpVector.x, 2), '\t', round(cf.UpVector.y, 2), '\t', round(cf.UpVector.z, 2))
	print('LookVector:\t', round(cf.LookVector.x, 2), '\t', round(cf.LookVector.y, 2), '\t', round(cf.LookVector.z, 2))
end

Here the results for a part with Position=(0, 0.5, 5) and Orientation=(0, 90, 0):

CFrameDetailed(somePart)
 CFrame:	    0, 0.5, 5, -4.37113883e-08, 0, 1, 0, 1, 0, -1, 0, -4.37113883e-08 

  Position:	     0    0.5   5
  RightVector:	 0    0    -1
  UpVector: 	 0 	  1 	0
  LookVector:	 -1   0 	0
7 Likes

4 posts were merged out for being off-topic.