The problem is I don't know how to get the direction of movement. Is it a hidden property of a part? Or a function? Or should I calculate it somehow? I have not found my answer for my question in the internet.
While CFrame.LookVector
is an option, it doesn't necessarily give the direction an object is moving if it doesn't rotate to face the direction where it's moving, nor does it tell whether or not the body is moving.
You can get the Unit vector of the object's Velocity
to get the direction of movement:
local vel = object.Velocity local direction if vel.Magnitude == 0 then direction = vel -- We can't get the unit vector of (0, 0, 0) where the body isn't moving, so we just return the same vector else direction = vel.Unit end