Direction of walk

How do I figure out the direction in which a npc will start moving towards? Like say I have a vector3 position, and I want to figure out the orientation of the direction of where the npc will move to. Thanks - BMWLux

1 Like

If you get the npc’s humanoidrootpart’s lookvector, you should get what you need.

Yeah but like i’m checking before he starts walking. Therefore its not in the direction of where he is walking.

You mean like?

local function GetMovementDirection()
	if math.round(HRP.Velocity.Magnitude) > 0 then
		return HRP.CFrame.LookVector
	end
end

If you want to find the direction character is walking, use Humanoid.MoveDirection
If you want to find the direction character is looking, use Character:GetPivot().LookVector

Wouldn’t the NPC rotate automatically? Try setting the RootPart’s LookVector to the position.

You can use CFrame.lookat, do:
local Direction = CFrame.lookat(Character.PrimaryPart.Position, Goal ector3Here).LookVector

GoalVector3Here must be replaced with your vector3 that the npc will walk to. I use “PrimaryPart” because that gets the HumanoidRootPart of the character. (if you set the primarypart correctly) After that I just get the lookvector of that cframe which is just the direction with a magnitude (length) of 1.

1 Like