Issue with player not walking right direction!

So I’ve got an issue with my mouse and camera scripts. The code will be below if you need it but it basically just makes the players camera above them, and it makes the player face the mouse.
mouse script:

local character = game.Players.LocalPlayer.Character
local mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
	local forwardVector = (character.HumanoidRootPart.Position - mouse.hit.Position).Unit
	local rightVector = forwardVector:Cross(Vector3.new(0,1,0))
	local cframe = CFrame.fromMatrix(character.HumanoidRootPart.Position, -rightVector, Vector3.new(0, 1, 0))

	character.HumanoidRootPart.CFrame = cframe
end)

camera script:

wait(3)
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local hrp = char.HumanoidRootPart
local cameraPart = workspace.cameraPart
local camera = workspace.CurrentCamera


while wait() do
	hum.AutoRotate = false
	camera.CameraType = Enum.CameraType.Scriptable
	cameraPart.Position = Vector3.new(char.Head.Position.x, 20, char.Head.Position.z)
	camera.CFrame = cameraPart.CFrame
end

The issue is the player always walks in the same direction, not where they are facing! Video:


I am pressing the W key the entire time in the above video, would it be possible to make the player walk to the mouses position instead when walking? Any help appreciated, thanks!

You will need a custom control script.

Like this one:

1 Like

It worked, thank you so much!
I also modified the camera script to this:

wait(3)
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local hrp = char.HumanoidRootPart
local cameraPart = workspace.cameraPart
local camera = workspace.CurrentCamera

	

hrp:GetPropertyChangedSignal("Position"):connect(function()
	game:GetService("TweenService"):Create(cameraPart, TweenInfo.new(1), {Position = Vector3.new(char.Head.Position.x, 20, char.Head.Position.z)}):Play()
end)
while wait() do
	hum.AutoRotate = false
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = cameraPart.CFrame
end

Just to make it smoother, and the final result is amazing!

2 Likes