I am working on a camera system for my build mode, however I want my camera to move at a constant speed, like it does in bloxburg, so I used cframes to make the camera move and it does just that and in the right direction, but over time it gains speed. How do I prevent it from gaining speed? I want the cameras speed to stay constant.
Local Script:
--Miscellaneous
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local initiate = game.ReplicatedStorage.Binds.InitiateBuildMode
local garageCam = workspace.Garage.FrontEndCamera
local garage = workspace.Garage
local connects = {}
local willEnd
--Services
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
--Configurations
local cameraSpeed = 0.09
local sensitivity = 500
local Y = 0
local function begin()
willEnd = false
connects.begin = UserInputService.InputBegan:Connect(function(input, processed)
while wait() do
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
if not collisionsDetected(camera.CFrame.Position, camera.CFrame.LookVector * 1.5) then
camera.CFrame = camera.CFrame + camera.CFrame.LookVector.Unit * cameraSpeed
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
if not collisionsDetected(camera.CFrame.Position, -camera.CFrame.LookVector * 1.5) then
camera.CFrame = camera.CFrame + -camera.CFrame.LookVector.Unit * cameraSpeed
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
if not collisionsDetected(camera.CFrame.Position, -camera.CFrame.RightVector * 1.5) then
camera.CFrame = camera.CFrame + -camera.CFrame.RightVector.Unit * cameraSpeed
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
if not collisionsDetected(camera.CFrame.Position, camera.CFrame.RightVector * 1.5) then
camera.CFrame = camera.CFrame + camera.CFrame.RightVector.Unit * cameraSpeed
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.Q) then
if camera.CFrame.Y <= garage.Ceiling.CFrame.Y - 1 then
camera.CFrame = camera.CFrame + camera.CFrame.UpVector.Unit * cameraSpeed
end
end
if UserInputService:IsKeyDown(Enum.KeyCode.E) then
if camera.CFrame.Y >= garage.Floor.CFrame.Y + 1 then
camera.CFrame = camera.CFrame + -camera.CFrame.UpVector.Unit * cameraSpeed
end
end
if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
local delta = UserInputService:GetMouseDelta()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
Y = delta.X / sensitivity
else
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
Y = 0
end
if willEnd then
for _, component in pairs(connects) do
component:Disconnect()
end
break
end
end
end)
script.Parent.X.MouseButton1Click:Connect(function()
willEnd = true
end)
RunService:BindToRenderStep("Update", Enum.RenderPriority.Camera.Value, rotateCamera)
end
function collisionsDetected(startingPosition, endingPosition)
local collision = workspace:Raycast(startingPosition, endingPosition)
if collision then
return true
end
return false
end
function rotateCamera()
camera.CFrame = camera.CFrame * CFrame.Angles(0, -Y, 0)
end
initiate.Event:Connect(begin)
