I’m trying to make a camera that is exactly like roblox studio’s camera, I have gotten close to make it but the camera seemed wobbly and so I gave up and came to the dev forum for help.
please hepl
thanks…
I’m trying to make a camera that is exactly like roblox studio’s camera, I have gotten close to make it but the camera seemed wobbly and so I gave up and came to the dev forum for help.
please hepl
thanks…
This is not the category for this, you should show code if you save some or look somewhere else for help.
You can look through the Freecan script Roblox implemented at runtime. game.Players.Player.PlayerGui
Hello! I have already implemented something like the studio camera before from one of my old games before, Put it in StarterPlayerScript
I hope this helps!
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local cameraPosition = CFrame.new() -- default camera position
local cameraMoveSpeed = 1 -- speed of the camera
local rotationSensitivity = 2.5 -- the sensitivity of the camera
local mouseDelta = Vector2.zero
local mouseHolding = false
repeat
camera.CameraType = Enum.CameraType.Scriptable
task.wait(1)
until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = CFrame.new() -- the camera rotations can be wonky
cameraPosition = camera.CFrame
local function getMoveDirection()
local moveDirection = Vector3.zero
if UserInputService.KeyboardEnabled then
if UserInputService:IsKeyDown(Enum.KeyCode.W) then
moveDirection += camera.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
moveDirection += -camera.CFrame.LookVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.A) then
moveDirection += -camera.CFrame.RightVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.D) then
moveDirection += camera.CFrame.RightVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.Q) then
moveDirection += camera.CFrame.UpVector
end
if UserInputService:IsKeyDown(Enum.KeyCode.E) then
moveDirection -= camera.CFrame.UpVector
end
end
return moveDirection * cameraMoveSpeed
end
RunService.RenderStepped:Connect(function()
local moveDirection = CFrame.new(getMoveDirection())
local rotation = CFrame.Angles(0, math.rad(mouseDelta.X), 0) * CFrame.Angles(math.rad(mouseDelta.Y), 0, 0)
cameraPosition = cameraPosition * moveDirection -- setting the camera position variable
camera.CFrame = cameraPosition * rotation -- setting the position and rotation
end)
UserInputService.InputChanged:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseMovement and mouseHolding then
local inputDelta = Input.Delta
-- so we could rotate the camera
mouseDelta = Vector3.new(
mouseDelta.X - (inputDelta.X / rotationSensitivity),
math.clamp(mouseDelta.Y - inputDelta.Y / rotationSensitivity, -80, 80)
)
end
end)
-- locking the mouse position like in studio
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
mouseHolding = true
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
mouseHolding = false
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.