When I substract a part position from another part position without .magnitude:
Where are those coordinates? [In between?, at the edge?]
If it were to make a part spawn at the difference between the 2 positions[p2-p1], where would it spawn?
Here is a test I did: I spawned a new part at the difference between both the 2 part’s positions [p2 -p1]. The new part spawned somewhere else randomly, why?
local p1 = game.Workspace:FindFirstChild("Part1")
local p2 = game.Workspace:FindFirstChild("Part2")
local distance = (p2.Position - p1.Position)
print(distance)
wait(4)
------------------------------------
local newpart = Instance.new("Part")
newpart.Position = distance
newpart.Size = p1.Size
newpart.Parent = workspace
-- Result: 40.6, -0.0008, 0.0379
Oh, I know about lerp, Im just trying under to understand vectors a little bit more, especially on the visual side. Like: where would a Vector be[In The Workpace] if you substracted 2 Vectors with one another, or divided, etc.
Right now, Im just focused on the substraction part.
Vector V which is at (1, 3)
And Vector Q which is at (3, -1)
To add V + Q I can start drawing the tail of Q at the head of V
That gets us a new vector of (4, 2).
Now for your question. Subtraction. Let’s do V-Q
Instead of drawing the tail of Q at V I’m going to draw the head of Q at V and use the position where the tail is as the answer.
That gave us a new Vector M which is equal to (-2, 4).
At first glance this might look like it isn’t all that useful, but that’s because we are missing one crucial piece to the puzzle. Let me draw the original Q back in as well.
Now with that there you might notice why M is useful. M is now the direction and distance you would have to travel from Q to get to V
To apply this into actual code…
Say you had a part at a position we will call target
And there was a character at a position we will call hrp
We can use vector subtraction to find how far in what direction that character will have to travel to get to target.
local target = game.Workspace.Target.Position
local hrp = game.Workspace.Character.HumanoidRootPart.Position
local direction = target - hrp
print("Character has to travel " .. direction)