Why do we subtract the position of PartA from PartB in every instance of using magnitude?
print((workspace.PartA.Position - workspace.PartB.Position).magnitude)
Why do we subtract the position of PartA from PartB in every instance of using magnitude?
print((workspace.PartA.Position - workspace.PartB.Position).magnitude)
It has to do a little bit with how physics works and basic vector addition/subtraction. The way that the character's position works is that it's tracked by a vector's magnitude from (0,0,0) and updated from there.
With this, subtracting someone's position from another position doesn't exactly return a distance, it returns another vector. The "magnitude" is simply the length of this vector, as a vector is defined by having both a magnitude and direction.
By subtracting the the position of PartB from PartA, you are getting a vector3 value which is the difference between the two values. For example, if you have a part at 100, 200, 100 and another at -50, -100, -50, the difference between the two positions would be 150, 300, 150. After you get the difference, you use .magnitude to basically get the length of a straight line from the position 0,0,0 to the difference between the positions of the two parts. Sorry if this explanation is a bit hard to understand.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
Magnitude in physics defines the length of a Vector, if we wish to calculate the distance between two points, we need to get a normal. This normal is the subtraction of the two Vectors; leaving us with the difference between each Vector point. That difference's magnitude defines the space between v1 and v2.
Think of it as how we define the space between two integers. If we wish to get the distance, we subtract each number. 18 - 15 = 3, therefore our distance is 3. However, Vector's a three-dimensional so this number isn't directly waiting for us. It's sitting in the calculated magnitude though, this is why we get the magnitude of the calculated result.
subtracting magnitudes gets one point to another, if A's mag is 5 and B's mag is 3 then out distance is 2 as Feahren said.