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

How to detect which direction an npc is walking?

I'm working with an NPC and am trying to enable/disable some billboard guis when it walks in certain directions. Nothing happens when I try this with the npc but it does work when I try this with the player

local camera = game.Workspace.CurrentCamera
local humanoid = script.Parent:FindFirstChild("Humanoid")
local pb1 = game.Workspace.Dummy:WaitForChild("Bag").pb1
local pb2 = game.Workspace.Dummy:WaitForChild("Bag").pb2

function Test(disabled)
	if (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) > 0) then --when the npc runs upwards or to the right, pb2 is no longer visible and pb1 becomes visible.
		pb1.Enabled = true 
		pb2.Enabled = false
	elseif (humanoid.MoveDirection:Dot(camera.CFrame.RightVector) < 0) then ----when the npc runs downwards or left, pb1 is no longer visible and pb2 becomes visible.
		pb1.Enabled = false 
		pb2.Enabled = true
	end
end

humanoid.Running:Connect(Test)

(not sure if this method is for the player's humanoid only)

1 answer

✓ Accepted answer

Use Humanoid.RootPart.AssemblyLinearVelocity.Unit or something. It'll get the relative unit to 1 stud.

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