Overhead view camera script seems to not make WASD work

So I was bored and I came up with a script that gives you a overhead view of your character but for some reason if it is exactly above the character WASD doesn’t work, but if I slightly angle the camera it begins to work but I want it to be exactly above the character is there anyway I could fix this?

local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera

player.CharacterAdded:Wait()
player.Character:WaitForChild("Head")

cam.CameraSubject = player.Character.Head
cam.CameraType = Enum.CameraType.Attach
cam.FieldOfView = 50


game:GetService('RunService').Stepped:Connect(function()
	local plheadposx = player.Character.Head.Position.x
	local plheadposy = player.Character.Head.Position.y
	local plheadposz = player.Character.Head.Position.z

	local headpos = Vector3.new(plheadposx, plheadposy+25, plheadposz)
	local lookheadpos = Vector3.new(plheadposx, plheadposy, plheadposz)
	cam.CFrame = CFrame.new(headpos, lookheadpos)
end)
1 Like

The reason why this happens is because, in the ControlModule (which is under StarterPlayer > StarterPlayerScripts > PlayerModule > ControlModule when you run the game), the module uses the field moveFunction to move the character around. The normal value for this is the Player:Move function.

Basically, the controls give a Vector3 movement direction relative to the camera, and the Player:Move function will interpret it as “relative to the camera.” When you make the camera point straight down, that makes “forward” relatively straight down, and the closest your character can go to straight down is nowhere.

The easiest way to fix this is to augment that moveFunction so that it rotates the move direction upwards, which would make “up” look like “forward” for your character.

And the easiest way I can think of doing that is by switching the Y and Z parts of the direction:

-- ControlModule, line ~103
function self.moveFunction(player, walkDirection, relativeToCamera)
	walkDirection = Vector3.new(
		walkDirection.X, 
		walkDirection.Z, 
		walkDirection.Y
	)
	player:Move(walkDirection, relativeToCamera)
end

I hope that helps!

1 Like