I tried to make a script that tp you to the middle position between two others but it didnt work. I hope i'll know why soon
Here is my script :
1 | local pos 1 = game.Workspace.PTest 1. Position |
2 | local pos 2 = game.Workspace.PTest 2. Position |
3 |
4 | local distance = (pos 1 - pos 2 ).magnitude |
5 |
6 | game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(distance / 2 ) |
You can use a function of CFrame
called lerp
With it, you can not only get the middle pos between two position, but pretty much any as long as you provide it as a perecentage.
1 | local pos 1 = workspace.PTest 1. CFrame |
2 | local pos 2 = workspace.PTest 2. CFrame |
3 |
4 | local middlePos = pos 1 :lerp(pos 2 , 0.5 ) --0.5 means 50% therefor the middle |
5 |
6 | game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = middlePos |
Roblox has a nice function called DistanceFromCharacter. I'd recommend using it.