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

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

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

✓ Accepted answer

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

1 comment

0

lol i am stupid

local midY = (part2.Position.Y - part1.Position.Y)/2

2 comments

0

it does not work properly when the height is -

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 +

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