Weird player movement with Top-down Camera

  1. What do you want to achieve?
    I made a top-down camera movement system, however occasionally, player movement gets messed up.

  2. What is the issue?
    As you can see here, I was holding A and D, it was supposed to make me go left and right but instead diagonally. The special thing about this is that it happens very very rare.

  3. What solutions have you tried so far?
    I looked far and wide on the developer hub. But I can’t seem to find one related to this, any help is greatly appreciated. Thanks :smiley:

Code for top down movement:

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

----- Variables -----
local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera

local depth = 17.25
local smoothiness = .085
local touched = false

----- Top down scripting -----
	if Player.Character and hit:IsDescendantOf(Player.Character) and hit:IsA("BasePart") and not touched then
		touched = true
		Camera.CameraType = Enum.CameraType.Scriptable
		RunService:BindToRenderStep("TopdownView", Enum.RenderPriority.Camera.Value, function()
			local char = Player.Character
			if char then
				local hrp = Player.Character:FindFirstChild("HumanoidRootPart")
				if hrp then
					Camera.CFrame = Camera.CFrame:Lerp( +, depth, 0), hrp.Position), smoothiness)

In short what the code does is that when player touches a part named “Start” The top down camera will be activated. This is a local script and it is put in StarterPlayer → StarterPlayerScripts

My best guess on what is happening is that as the LookVector of the camera changes from the direction it was facing to the direction it needs to face in order to perform the top-down camera, it isn’t quite getting axis-aligned along X and Z before hitting its straight-down point. This “cements” the camera in that direction, since the camera technically isn’t facing any direction along the X-Z plane, and so your player moves diagonally.

The easiest way I have seemed to avoid the issue is to slightly rotate the camera so it isn’t technically straight down but instead has some directionality. You still get a bit of the effect during the initial lerp pan, but it smooths out as the camera does. Even a rotation of 1 degree along the X-axis seemed sufficient to keep my character walking straight (after the main lerp) and was also unnoticeable visually.

A more robust but also more complex solution would be to fork the default ControlModule to add a state that never moves the character relative to the camera. This would give you perfect results but would also mean that your camera must always be axis-aligned, or else movement will not match the camera angle.

1 Like