I do not need help with any code. My code is function. I'm just wonder the why.
Subtracting one Vector3 from another gives you the direction. Sometimes, however, I'm not sure whether to use A - B
or B - A
. There is a clear difference between the two. This can be easily demonstrated when I was trying to make a robot retreat a few steps.
--Made the bot move backward, as intended. local direction = (bot.Torso.Position - plr.Character.Torso.Position) bot.Humanoid.WalkToPoint = bot.Torso.Position + (direction.unit*10) --Made the bot move forward, instead of backward. local direction = (plr.Character.Torso.Position - bot.Torso.Position) bot.Humanoid.WalkToPoint = bot.Torso.Position + (direction.unit*10)
Aside from this example, basic arithmetic tells us that 5 - 3
will have a different answer than 3 - 5
. I was simply wondering what the difference in the context of Roblox is, and when to know which Vector3 to put first.
They're very simply inverses of each other. Vector3s don't have any fancy math behind them, just simple subtraction.
The general rule for "forward" (your second example) is final minus initial, or in this case, the goal position minus the current position. To go backwards, just invert it.
EDIT: As a side note, |5 - 3| = |3 - 5|
. Gotta love absolute values.