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

Using Lines to calculate Distance?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

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

Ad

Answer this question