Suppose that I have two parts like the ones in the picture. If I stand on the edge of Part A, how do I teleport to Part B but retain the position I had at Part A?
If I were to use something along the lines of:
Player.Character:MoveTo(PartB.CFrame)
I would end up teleporting to the center of this part which is not what I want. I have done some research on :ToObjectSpace() and :ToWorldSpace() however I cannot seem to get these to work. Examples would be much appreciated.
Something like this will help.
The floor its partA and partB, and Im using another little part for the “player” called PLY
Just substract from the origin position of partA - player’s position to get the offset. The distance at which the player is away from the center of partA in coordinates.
Then use that offset to be substracted from the target position of partB
If you run this code in CommandBar you will see the player part its teleported to the correct coodinate, you just need to add an offset in Y axis too, so the player dont get inside the ground
local partA = game.Workspace.PartA
local PLY = game.Workspace.PLY
local partB = game.Workspace.PartB
local offset = partA.Position - PLY.Position
PLY.Position = partB.Position - offset
Thanks a bunch. After testing this code to see the exact same problem arising (being teleported ~200 studs away from the intended area), I noticed that the code I had previously (utilizing ToObjectSpace) worked. It was just that it calculated the position multiple times during the teleportation which led to that occurrence.
I’ll mark this as solution since it helped me debug.