roblox ToWorldSpace example code

Example: roblox what does toobjectspace and toworldspace do

CFrame:toWorldSpace(cf)
This method converts a cframe in object space to a cframe in world space . In other words it takes cf (which is relative to CFrame ) and returns a result that is relative to the origin. For example, if I have a cframe called cf1 which is defined to be CFrame.new(0 , 10 , 0) and I have another cframe relative to cf1 called cf2 which is CFrame.new(1 , 0 , 0) , cf1:toWorldSpace(cf2) will return a cframe in world space that is relative to the origin/identity cframe .

CFrame:toObjectSpace(cf)
This method does the exact opposite. Given a CFrame (let’s call it cf1 ), and an input CFrame (call it c2 ), it will return a result representing the cframe cf2 is in relative to cf1 . For example, if an input CFrame defined CFrame.new(5 , 1 , 3) is given, CFrame.new(1 , 1 1):toObjectSpace(cf) will return CFrame.new(4 , 0 , 2) because that is the CFrame the input is in relative to CFrame.new(1 , 1 , 1)

Tags:

Misc Example