Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone please explain .Unit to me as well as it's application?

1 answer

It normalizes the vector so that it has a magnitude of one. Say I wanted to get the direction from part1 to part2; I can do so by subtracting part1's position from part2's position, and getting the unit of that. An example use of the direction would be to move part1 five studs toward part2.

--Remember to make sure Part1 and Part2 are both valid parts in workspace and both anchored for this example to work.

local part1, part2 = workspace.Part1, workspace.Part2

local direction = (part2.Position - part1.Position).Unit
part1.CFrame += direction * 5

https://developer.roblox.com/en-us/api-reference/datatype/Vector3

This discussion is preserved as it was. New answers, comments, and votes are closed.