Yeah, you’ve got it right. What exactly do you need assistance with? Do you just need to define moveDirection? If so, that would just be the normalized velocity of the part (e.g. part.Velocity.Unit).
So you could do the following:
local dot = rootPart.CFrame.LookVector:Dot(rootPart.Velocity.Unit)
if dot > 0 then
-- Forward
elseif dot == 0 then
-- Sideways
else
-- Backward
end
Ah, fair point. There’s a few ways to check for that. NAN can be checked just by checking if the number is equal to itself. If not, it’s NAN. (e.g. if dot ~= dot then -- it's nan) But you could also just check if the movement is close to 0:
local dot
if rootPart.Velocity.Magnitude > 0.001 then -- Arbitrary small number check
dot = rootPart.CFrame.LookVector:Dot(rootPart.Velocity.Unit)
end
if not dot then
-- Not moving
elseif dot > 0 then
-- Forward
elseif dot == 0 then
-- Sideways
else
-- Backward
end