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

Help with math?

Asked by
Damo999 182
9 years ago

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)
0
How would it stretch? Do you mean, the range from p1 to p2? E.G 2 and 3, range is 1 TheDeadlyPanther 2460 — 9y
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. Damo999 182 — 9y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

2
Lerp is a little less clear than just arithmetic average: (p1 + p2) / 2 BlueTaslem 18071 — 9y
Ad

Answer this question