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

How do I calculate middle Y position between parts A and B?

Asked by
NsNidPL 41
5 years ago

Hello, how do I calculate middle Y position between parts A and B? Example: Part A has Y position of 0, and part B has Y position of 20. I want the result to be 10. I also want it to work negatively.

2 answers

Log in to vote
1
Answered by 5 years ago

You basically calculate the average between the y position of both parts. ((y1 + y2) / 2)

0
lol i am stupid NsNidPL 41 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
local midY = (part2.Position.Y - part1.Position.Y)/2
0
it does not work properly when the height is - NsNidPL 41 — 5y
0
then use an if statement to check for both of parts, for example if part1 y position is negative and part2 y position is positive or vice versa then use this formula: midY=(part1Y + part2Y)/2, but make sure you put negtive on the first place, if both are positive use the formula I sent first, and if both are negative use the formula from this comment, using + g1o2r3d4a5n6 350 — 5y

Answer this question