Is there a way to prevent the character from moving right, left, or backward

If not I’ll add bodyvelocity and set Humanoid.AutoRotate to false, but

  1. performance: Making a body velocity, adding it, then deleting it takes more time than changing a property/setting (fast paced close combat)
  2. less likely to bug or glitch
  3. cleaner script

AutoRotate should handle that alone

AutoRotate is the directiont the character is facing, not movement. Im trying to prevent the character from going left, back, or right too.

edit: and I want the character to continue moving at walkspeed, with no jitter from changing movement method

Try using a physics force and only register input from the W, for example a power value and holding W will set the power value, and use the camera to indicate direction while multiplying by the power?

Here is how you can do that
If you want the player not able to change camera position then set AutoRotate to false

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")

RunService.RenderStepped:Connect(function()
	if humanoid and hrp then
		local moveDir = humanoid.MoveDirection
		local forwardDir = hrp.CFrame.LookVector

		local dot = moveDir:Dot(forwardDir)

		if dot <= 0.5 then
			humanoid:Move(Vector3.zero, false)
		end
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.