A unit vector is literally a direction. They are LookVectors, and are found by RayCasts, or by using (Position1-Position2).Unit
to obtain the direction between one point and another. A unit vector is a direction. However, how can I obtain a rotation from a unit vector? I need to set an orientation of a part so the part will face the direction of the unit vector? How can I do that?
The easiest solution to this would be to point the part using CFrames
. The second argument of a CFrame
may be a position that the CFrame's
direction values will be 'pointed' at, which is perfect in your case.
Here's an example:
part.CFrame = CFrame.new(part.Position, part.Position + unit)
However, keep in mind that this wont output the rotation directly, it'll only rotate the CFrame
.
How to get rotation from a CFrame
By simply subtracting the Position component of a CFrame from itself, we can get the rotational values.
local ang = Vector3.new(part.CFrame - part.CFrame.Position) -- Gets rotation ang = Vector3.new(math.deg(ang.X), math.deg(ang.Y), math.deg(ang.Z)) -- Converts rotation into degrees