Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to get a specific position between two positions ?

Asked by 6 years ago

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 :

local pos1 = game.Workspace.PTest1.Position
local pos2 = game.Workspace.PTest2.Position

local distance = (pos1 - pos2).magnitude

game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(distance / 2)
0
Just use (pos1+pos2)/2. You can add and divide vectors. abnotaddable 920 — 6y

3 answers

Log in to vote
2
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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.

local pos1 = workspace.PTest1.CFrame
local pos2 = workspace.PTest2.CFrame

local middlePos = pos1:lerp(pos2, 0.5) --0.5 means 50% therefor the middle

game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = middlePos
0
who the heck downvoted this, i gave an upvote and it was at +1 and now it's at 0. User#19524 175 — 6y
0
because theres a much easier method. abnotaddable 920 — 6y
1
but that's not a reason to downvote this answer. in fact you should be using this method. User#19524 175 — 6y
Ad
Log in to vote
2
Answered by
tukars 17
6 years ago
Edited 6 years ago

Just do (pos1+pos2)/2. Its as easy as that

Log in to vote
0
Answered by
oftenz 367 Moderation Voter
6 years ago
Edited 6 years ago

Roblox has a nice function called DistanceFromCharacter. I'd recommend using it.

0
Thank you for this but i would like to get the exact middle position. Let's say there's Two caste. Between those 2 castle, there's a part and i want to tp to this part without knowing its position NotZuraax 68 — 6y
0
DistanceFromCharacter is deprecated from what I've heard. User#19524 175 — 6y

Answer this question