Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with math?

Hey guys how would I go about adjusting p3 to stay in between point p1 and p2.

When I run the script p3 gets put onto p2 instead of stretching from p1 to p2

I hope that makes sense.

p1 = script.Parent.Part1
p2 = script.Parent.Part2
p3 = script.Parent.Part3
p3.Anchored = true
p3.CanCollide = false


length = (p1.Position - p2.Position).magnitude
print(length)
p3.CFrame = p1.CFrame +Vector3.new(length,0,0)

function stretch(PointA,PointB)
	PointA.Size = PointA.Size +Vector3.new(length/2,0,0)
end
stretch(p1,p2)

2 comments

0

How would it stretch? Do you mean, the range from p1 to p2? E.G 2 and 3, range is 1

0

Stretch means the Size so p3 would start at p1 and go to p2, the problem i am facing is the parts size is long enough to reach p2 but instead of going from p1 to p2 p3 stays on p1 and doesn't go to p2.

1 answer

If PointA is a part that you want to span from p1 to p2, use linear interpolation (lerp) and CFrame with 2 arguments.

PointA.Size=Vector3.new((p1.Position-p2.Position).magnitude,PointA.Size.Y,PointA.Size.Z)
PointA.CFrame=CFrame.new(p1:lerp(p2,.5),p2)

p1:lerp(p2,.5) is .5 of the way from p1 to p2. From this position, the CFrame is set to look at p2.

1 comment

2

Lerp is a little less clear than just arithmetic average: (p1 + p2) / 2

This discussion is preserved as it was. New answers, comments, and votes are closed.