-
What do you want to achieve?
I made a top-down camera movement system, however occasionally, player movement gets messed up. -
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.
https://gyazo.com/0806467d5fc8c0857ca2576334d6db13.mp4 -
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
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 -----
workspace.Start.Touched:Connect(function(hit)
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(CFrame.new(hrp.Position + Vector3.new(0, depth, 0), hrp.Position), smoothiness)
end
end
end)
end
end)
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