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

Using Lines to calculate Distance?

Hello, i'm working on an experiment which revolves around gravity and how bodies interact in a vacuum. The thing is, if you don't know, distance makes a big deal with that(As close as you are to a body, the faster you get pulled by it.). So i want to draw a line from a body to another so that i can calculate the size of the line and how strongly the gravity actuates. Help please, thank you.

1 answer

You wont need to draw a line for this (Unless it's for visual reasons). Just use magnitude.

local BodyA = -- object1 --
local BodyB = -- object2 --

local Distance = (BodyA.Position - BodyB.Position).Magnitude
print(Distance)

This will print the distance between two objects, modify it for your own uses. For more information I recommend checking out Roblox Dev Hub

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