This post has been erased by the owner
They are a way to convert world positions to relative positions and visa versa, I used them a bunch for setting the position of attachments before you could set the WorldPosition
of them.
There pretty self explanatory (kind of), they transform points or vector3s into either WorldSpace or ObjectSpace relative to the CFrames that called them. ObjectSpace (in this case) meaning that the vector3 that you give it (PointToObjectSpace) will become relative to the CFrame that called it. And Worldspace essentially meaning the vector3 that you give it will become relative to 0,0,0
the origin of the world. it will be transformed from object/local space to worldspace.
So, for example, if i had a CFrame at 55,10,9
and called the point to object space method like CFrame.new(55,10,9):PointToObjectSpace(vec)
where vec can be for example Vector3.new(100,100,100)
it would return the position of 100,100,100
as if 55,10,9
were the origin in world space (0,0,0
), which would make the vector 100,100,100
into 45, 90, 91
., because again the origin of the world is now 55,10,9
not 0,0,0
PointToWorldSpace
is the opposite, doing CFrame.new(55,10,9):PointToWorldSpace(Vector3.new(45, 90, 91))
would give us 100,100,100
. it is transforming Vector3.new(45, 90, 91)
to world space.
As for an example, there are a lot of useful cases where you can use these methods to simplify certain tasks and quite a few things you can do just with the methods alone. Using PointToObjectSpace
you can tell when a Vector3 is behind or infront of part, in this case specifically the Player’s HumanoidRootPart Position.
Code
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Part = game.Workspace.Part
while true do
wait()
local CF = CFrame.new(HumanoidRootPart.CFrame.Position)
local vec = CF:PointToObjectSpace(Part.Position)
if vec.Z > (Part.Size.Z * .5) then
print("INFRONT!")
Part.Color = Color3.fromRGB(0,255,0)
elseif vec.Z < (-Part.Size.Z * .5) then
print("BEHIND!")
Part.Color = Color3.fromRGB(0,0,255)
else
print("MIDDLE!")
Part.Color = Color3.fromRGB(255,0,0)
end
end
Additional resources:
https://developer.roblox.com/en-us/api-reference/datatype/CFrame