How in the world do I determine the direction a character is moving in?

This is a problem I have been searching for the answer off for a very long time.

How in the world do I determine the direction a character is moving in?

And I mean any character. Not just the players character, so using simple keybinds and stuff will not work, as this could be for an NPC, of which doesnt have keybinds.

Before someone says Humanoid.MoveDirection, I would love to use this property, and its my goal to figure out how to use it. The problem is that it is based on the Camera of the player.

Along with that MoveDirection doesnt appear to update if its not a player.

Now a last resort effort would be to just use a some form of loop (or RunService.HeartBeat or RenderedStep) in order to tell the overall direction the character is moving in, but I’d rather not use one of those.

So is there a way to do this? Or is my best bet just using what I said above?

try checking this post, may help you!

1 Like

Sad to say but this post doesnt fit my needs, as I stated above MoveDirection doesnt work with NPCS, and characters like that.

Thank you for trying though,

1 Like

Howdy, Fro!

Can you give an example (code snippet) of your NPC movement?
Would help a lot to diagnose some of the issues you may be having.
Thanks.

1 Like

I swear it’s the Normal vector of a CFrame (whether that be the Head or Torso or whatever else), but I can’t remember the implementation.


There’s a LookVector for all CFrames, which might be it. Enemies in my current project get knocked back (based on the direction they are facing, which is also the direction they move in for my case) with this code:

local function flyEnemyBackwards()
	local lookVector = humanoidRootPart.CFrame.LookVector 
	local pushBack = Instance.new("LinearVelocity")
	local finalVector = (-lookVector * 85 ) + Vector3.new(0,25,0)
	pushBack.VectorVelocity = finalVector
	pushBack.ForceLimitsEnabled = true
	pushBack.MaxForce = math.huge
	pushBack.Parent = humanoidRootPart
	pushBack.Attachment0 = humanoidRootPart.Attachment0

	pushBack.Enabled = true
	task.wait(0.2)
	pushBack:Destroy()				
end

I’m using Roblox’s AutoRotate feature with Humanoids in addition to the MoveTo() function for the actual movement stuff. I think you have to assume for my code though that the player is moving the same direction they face. :sweat_smile:

2 Likes

Can you just check the character’s velocity to see the direction they’re going in?