How would I teleport the player onto a certain position on a part relative to the player position?

Hey there! The title might be a little confusing, so I will break it down.

So let’s say the player is the purple circle. I want to move the player to the red circle on the line, so the player lines up with the line.

This is what I currently have:

local distance = (lowestPoint.Position - humanoid.RootPart.Position).Magnitude
humanoid.RootPart.CFrame = v.CFrame
humanoid.RootPart.Position = humanoid.RootPart.Position - humanoid.RootPart.CFrame.LookVector*(distance/2)

This does what I want it to do, but it obviously looks really weird since the player gets teleported twice. It could just be that I’m being stupid, but that’s for you to decide. Any help is appreciated!

1 Like

What is v.CFrame set to? You are also setting both the hrp cframe and position which will move the player twice.

1 Like

Well instead of teleporting the player twice, you could calculate the position where the player should be place

-- Assuming v is the red circle's part
local lineDirection = (v.Position - lowestPoint.Position).Unit
local playerPosition = v.Position - lineDirection * (distance / 2)
humanoid.RootPart.CFrame = CFrame.new(playerPosition)

v.CFrame is that line in the drawing. And yes, I am moving the player twice, the CFrame part is to line the player up first.

It only seems to work when the player is looking in a certain direction. I should’ve also clarified that v is the line. Lowestpoint is the point that is the lowest of the 2. There’s 1 point on each end of the line.

So the CFrame calculation needed to be adjusted. Sorry about that

-- Assuming v is the red circle's part representing the line
local lineDirection = (v.Position - lowestPoint.Position).Unit
local playerPosition = v.Position - lineDirection * (distance / 2)
local lookAtPosition = v.Position + lineDirection * (distance / 2) -- Adjust to look along the line

humanoid.RootPart.CFrame = CFrame.new(playerPosition, lookAtPosition)
1 Like

Hm, the same issue occurs, where it only works if I look away from the lowest point and towards the highest point. If I look away from the highest point it just teleports me into the lowest point. Tell me if you need any more clarification, and thanks for the help.

1 Like

Could you please provide more context or explain the behavior you’re aiming for with this code?

2 Likes

So basically, I’m making a zipline system, where you can attach to a zipline at any location of the line. I’m just having trouble positioning the player onto the zipline itself.