Is there a .Magnitude for orientation?

Is there a .Magnitude for orientation?
Or how do I calculate how close a rotational degree is to another rotational degree?

Can you explain what your trying to do a bit more clearly?

Are you trying to check the length from one angle to another angle?

Take the difference between both degrees using math.abs(because degrees aren’t always positive math.abs gets the absolute value of a number which is always positive)?

Since Orientation is a Vector3 value, you can do something like this:

local FirstOrientation = Vector3.new(5, 5, 5)
local SecondOrientation = Vector3.new(10, 10, 10)

local OrientationDifference = (FirstOrientation - SecondOrientation)
local OrientationMagnitude = OrientationDifference.Magnitude

print(OrientationMagnitude) -- 8.66025447845459
print(OrientationDifference.X, OrientationDifference.Y, OrientationDifference.Z) -- -5, -5, -5

Don’t forget to mark this post as a solution if this helped :slightly_smiling_face:

Yes. The is a .Magnitude for Orientation.

local Part = Instance.new("Part", workspace)
Part.Parent = workspace
local Goal = Part.Orientation+Vector3.new(40, 0, 0)

while true do
    if Part.Orientation.Magnitude < Goal.Magnitude then
        Part.Orientation += Vector3.new(1, 0, 0)
    else
        Part:Destroy()
        print("Part reached the goal.")
    end
end

Turn them into vectors and do math.acos(direction1:Dot(direction2)) ?

3 Likes

No, there is not. Simply because rotation resets and is clamped to 180 degrees, so moving past that resets it and will provide an inaccurate measurement. However, this doesn’t apply to unit vectors like LookVector, but they always have a magnitude of one, unless you meant a comparison of two.

Edit: you can also compare the rotation using the dot product, though it is only one axis.

For that you need to use the Dot Product:

local orientation_1 = Vector3.new(90,0,0)
local orientation_2 = Vector3.new(0,90,0)

local orient_to_cf_1 = CFrame.Angles(math.rad(orientation_1.X),math.rad(orientation_1.Y),math.rad(orientation_1.Z))
local orient_to_cf_2 = CFrame.Angles(math.rad(orientation_2.X),math.rad(orientation_2.Y),math.rad(orientation_2.Z))

local dot_product = orient_to_cf_1.LookVector:Dot(orient_to_cf_2.LookVector)
local angle = math.acos(dot_product)
print(angle)

Remember! The angle will be in radians and not degrees! You can convert to degrees using math.deg(angle_in_radians)

1 Like

I think the dude forgot to check his messages.

For real.