Top - Down Camera Script Causing Character To Glitch Way Out When Going Up Stairs

I am completely stumped. Logged. Planked. Bolted. Decked. Stepped on. This makes no sense.
I have a fairly basic script, a top down camera and a player-look-to-mouse script

wait (7)
-- VARIARABABLES
local plr = game.Players.LocalPlayer
local char = plr.Character or plr:CharacterAdded()
local mouse = plr:GetMouse()

-- TOP DOWN CAMERA SCRIPT
game["Run Service"].RenderStepped:connect(function()
     workspace.CurrentCamera.CFrame = CFrame.new(plr.Character.HumanoidRootPart.Position + Vector3.new(0, 50, 0), plr.Character.HumanoidRootPart.Position)
end)

-- LOOK AT MOUSE SCRIPT (NOT PROBLEMATIC!! DON'T WORRY)
local function lookAtMouse()
   local mpos = mouse.Hit.p
   local lookVector = Vector3.new(mpos.X, plr.Character.HumanoidRootPart.CFrame.Y, mpos.Z)

   local target = CFrame.new(plr.Character.HumanoidRootPart.CFrame.p, lookVector)
   plr.Character.HumanoidRootPart.CFrame = CFrame.new(plr.Character.HumanoidRootPart.CFrame.p, lookVector)
end

game["Run Service"].RenderStepped:connect(lookAtMouse)

And it works! I can walk around, jump, ride a skateboard, anything!
But going up stairs is too far?

Stair bug video:

https://gyazo.com/9626eacabf4d6cf06d1cd20f9e46cbbb

I have the place file here so you can check it out for yourself.
stairs.rbxl (26.1 KB)
The script seen above is in StarterPlayerScripts

  • I removed all other scripts already.
  • I can go up the stairs if the script is disabled.
  • It happens with R6 too
  • It isn’t a malicious plugin
  • It may be a Roblox bug

Any suggestions, ideas or general solutions to this?

[ SOLUTION - ADD 0.05 STUDS Z OFFSET TO THE CAMERA ]

1 Like

I am not sure why this is happening, but the problem was fixed when I added -1 stud offset on camera’s x-axis, just like author of https://education.roblox.com/en-us/resources/arcade-game-top-down-camera (Roblox Dev Hub, 2021-04-7) did. Looks like this offset is required for smooth experience. If we don’t account for that, HumanoidRootPart for some reason is destroyed if y-axis offset is low and player jumps, or y-axis offset is higher, but player stands on high objects.

Here is your script that works with stairs as well. I added some small improvements. Have a nice day!

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

local CAMERA_OFFSET = Vector3.new(-1,50,0)

local camera = workspace.CurrentCamera
local mouse = Players.LocalPlayer:GetMouse()
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local HRP = character:WaitForChild("HumanoidRootPart")

local _rootCF, _mousePos

camera.CameraType = Enum.CameraType.Scriptable

local function cameraMovement()
	_rootCF = HRP.CFrame
	camera.CFrame = CFrame.new(_rootCF.Position + CAMERA_OFFSET, _rootCF.Position)
	
	_mousePos = mouse.Hit.Position
	_mousePos = Vector3.new(_mousePos.X, _rootCF.Y, _mousePos.Z)
	HRP.CFrame = CFrame.new(_rootCF.Position, _mousePos)
end

RunService:BindToRenderStep("CameraMovement", Enum.RenderPriority.Camera.Value, cameraMovement)
1 Like