We use cookies on this site to enhance your user experience
Collapse Sidebar




MoveDirection is a read-only property that describes the direction a Humanoid is walking in, as a unit vector along the X/Z axis. The direction is described in world space.

Because the property is read-only, it cannot be set by a Script or LocalScript.

The animation below visualizes the property:
A visualization of the MoveDirection property.

Code Samples

Walking Camera Bobble Effect

This LocalScript makes the camera bobble as the player’s character walks around, utilizing both the Humanoid’s CameraOffset and MoveDirection.
It should be parented inside of the StarterCharacterScripts so that it is distributed into a player’s character as expected.

local RunService = game:GetService("RunService")

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function updateBobbleEffect()
	local now = tick()
	if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
		local velocity = humanoid.RootPart.Velocity
		local bobble_X = math.cos(now * 9) / 5
		local bobble_Y = math.abs(math.sin(now * 12)) / 5
		local bobble = Vector3.new(bobble_X,bobble_Y,0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)
		-- Scale down the CameraOffset so that it shifts back to its regular position.
		humanoid.CameraOffset = humanoid.CameraOffset * 0.75

-- Update the effect on every single frame.