I want to understand how this line of code works:
print((workspace.Part.Position - Player.Character.HumanoidRootPart.Position).Magnitude)
I feel like I slightly understand it but I just want to clarify that I do.
I want to understand how this line of code works:
print((workspace.Part.Position - Player.Character.HumanoidRootPart.Position).Magnitude)
I feel like I slightly understand it but I just want to clarify that I do.
It’s basically just printing how far is the workspace.Part.Position
from the player character.
More detailed explanation:
(workspace.Part.Position - Player.Character.HumanoidRootPart.Position).Magnitude
workspace.Part.Position and Player.Character.HumanoidRootPart.Position both returns a Vector3. The ().Magnitude
will return the distance between two position in studs, in your case the distance between Part and HumanoidrootPart
Subtracting one Position from another gives you the vector that exists between the two Positions and its direction is toward the first Position. The Magnitude gives you the straight line distance between the two.
So, (VectorPosition1 - VectorPosition2) == VectorPosition3
? I think I’m slowly understanding.
I am still a little confused is there anyway you can help explain it a different or more simpler way? I am not very good when it comes to math stuff lol.
No, it’s more like:
(VectorPosition1 - VectorPosition2).Magnitude == A number that represents the distance between those two parts but into studs
so instead of getting (1,3,4) or something like that, you’ll get a number instead.
Thanks for the explanation. Hopefully I understand this time.
My understanding: So the .Magnitude
converts it to studs?
Yes, magnitude converts the distance between two vectors from vector3 to studs.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.