How to separate character movement from camera direction

I’ve been trying to create a freelook system for first person use, however the biggest problem is that the character will move to where the camera is pointing if your holding down W. Would they be anyway to counteract this?

I’ve tried disabled the humanoid autorotation but it did not come to fruition.

2 Likes

You could try changing the camera mode.

You can manually create a custom control script to control the Humanoid character every render step like in this post which will allow you to manually control where the character chooses to move with Humanoid:Move(). You can also edit it so you can make the movement relative to how the Humanoid is facing and such but yeah the general concept is making your own by overwriting the default Humanoid controls.

Here is a local script that will move the character relative to the world and not the camera.
In starter player scripts:

local RunS = game:GetService("RunService")
local InputS = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()

player.CharacterAdded:Connect(function(_character)
	character = _character
end)

local walkKeyBinds = {
	Forward = { Key = Enum.KeyCode.W, Direction = Enum.NormalId.Front },
	Backward = { Key = Enum.KeyCode.S, Direction = Enum.NormalId.Back },
	Left = { Key = Enum.KeyCode.A, Direction = Enum.NormalId.Left },
	Right = { Key = Enum.KeyCode.D, Direction = Enum.NormalId.Right }
}

local function getWalkDirectionCameraSpace()
	local walkDir = Vector3.new()

	for keyBindName, keyBind in pairs(walkKeyBinds) do
		if InputS:IsKeyDown(keyBind.Key) then
			walkDir += Vector3.FromNormalId( keyBind.Direction )
		end
	end

	if walkDir.Magnitude > 0 then --(0, 0, 0).Unit = NaN, do not want
		walkDir = walkDir.Unit --Normalize, because we (probably) changed an Axis so it's no longer a unit vector
	end
	
	return walkDir
end

local function updateMovement( dt )
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid:Move( getWalkDirectionCameraSpace())
	end
end	

RunS.RenderStepped:Connect(updateMovement)

5 Likes

Thanks, I’ll try it out tomorrow.

Thanks alot! This really helped, I’ll edit it to my liking until it’s perfect.

Sorry if I’m asking too much but, let’s say I was walking walking left and using “W” and the camera to go in that direction this is when I’m not freelooking however, when I start freelooking and I was still holding “W” it would cause me to turn right and start going north or forwards. What would remedy this?