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

How do I find out the direction of movement of an object/part?

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.

1 comment

2

CFrame.LookVector

1 answer

✓ Accepted answer

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

3 comments

0

As I understand velocity.Magnitude is a speed, but what is Velocity.Unit, can you explain it? I can't find docs for that

1

The unit vector describes the direction of the given finite vector. The unit vector doesn't really exist if the body which the vector represents isn't moving. This is the equivalent of the magnitude vector being 0, since magnitude can describe velocity as well as distance.

1

To add on to what DeceptiveCaster has said, unit vectors have a magnitude of 1

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