Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix the camera to only move on one axis?

Asked by 4 years ago

I currently have this script that locks a top-down view, but I want the camera to only move when the w or s keys are clicked, and not to when pressing a and d. I don't want to disable the a and d keys, as that stops movement.

local offset = Vector3.new(-5,50,0)
local fieldOfView = 30
local player = script.Parent.Parent
local camera = game.Workspace.CurrentCamera
local runService = game:GetService("RunService")

camera.FieldOfView = fieldOfView
local function onRenderStep()

local playerPosition = player.Character.HumanoidRootPart.Position
local cameraPosition = playerPosition + offset
camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
end

runService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onRenderStep)

Answer this question