Hi,
at the moment I am trying to understand the concept of Object Space in CFrame and trying to see what Part.CFrame:ToObjectSpace(cf) does. I know that this should return part’s CFrame relative to cf. I think It’s as if you are using cf as an origin instead of the world origin.
I have this code:
local originPart = Instance.new("Part", game.Workspace)
originPart.Anchored = true
originPart.CanCollide = false
originPart.BrickColor = BrickColor.Random()
originPart.CFrame = CFrame.new(0,0,0)
originPart.Name = "originPart"
local newPart = Instance.new("Part", game.Workspace)
newPart.Anchored = true
newPart.CanCollide = false
newPart.BrickColor = BrickColor.Random()
newPart.CFrame = CFrame.new(0,0,4)
newPart.Name = "newPart"
local resultPart = Instance.new("Part", game.Workspace)
resultPart.Anchored = true
resultPart.CanCollide = false
resultPart.BrickColor = BrickColor.Random()
resultPart.CFrame = newPart.CFrame:ToObjectSpace(originPart.CFrame)-- The resultPart's cframe is the cframe of newPart Relative to originPart
resultPart.Name = "resultPart"
I have 3 parts where one is being used as the “origin” (originPart), one is being used as a random part (newPart) and the last one to show the relative cframe between the other two.
Before executing my code, I was expecting the resultPart to have the same position as newPart.
This is the result:
The resultPart seems to have moved to the opposite direction, in front of the originPart. Can someone explain why?
This might be wrong but does this happen because it takes the originPart’s lookvector which is 0,0,-1 opposite of the backvector which is 0,0,1?
Please correct me If I have said something incorrrect.
EDIT:
Hmm, I think I get it now. When I try to translate 0,0,4 relative to the originPart, I am attempting to put it 4 studs in front which in world position happens to be 0,0,-4.