This script pretty much make the camera follow the mouse like in this video
Problem: Player spawn camera is titled by 10
This is because the maxTilt = 10
and the updateCamera
function updates the camera, making the camera be titled when player joins.
How do I make the camera have no tilt when the player joins?
Code:
--=========================================================================================================
--STARTERPLAYERSCRIPTS >> CORE >> LOCAL SCRIPT
--=========================================================================================================
--<<VARIABLES>>
local cam = workspace.CurrentCamera
local camPart = workspace.MainMenu:WaitForChild("CameraPart")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local mainMenu = script.Parent.MainMenu
local maxTilt = 10
--=========================================================================================================
--<<FUNCTIONS>>
-- Function to handle camera tilt based on mouse movement
local function updateCamera()
cam.CFrame = camPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
end
-- Function to stop camera movement and reset to player's view
local function resetCamera()
cam.CameraType = Enum.CameraType.Custom
end
-- Connects a RenderStepped function to update the camera's CFrame based on mouse movement
game:GetService("RunService").RenderStepped:Connect(function()
if mainMenu.Value == "Play" then
resetCamera()
else
updateCamera()
end
end)
--=========================================================================================================
--<<NOTES>>
-- This LocalScript adjusts the orientation of the camera based on mouse movement
-- It sets the CameraType to Scriptable and continuously updates the camera's CFrame to simulate tilting
-- The maxTilt variable defines the maximum tilt angle for the camera
-- If mainMenu's value is "Play," it stops camera movement and resets to the player's view
--=========================================================================================================