So I’ve got my first person script below (got from devforum) that toggles on and off via a remote event from my main server script, my issue is that when I toggle the camera back to custom (from scriptable) everything is fine except for that I can’t move the free-view camera around (CFrame orientation or position (or both) is pretty much locked). It has something to do with the MouseMovement input function but I’m not sure how I’d go about fixing it. I’ve attached a video of the issue and my code (I’ve tried to wittle it down as much as I can, sorry if it’s long.)
local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local m = player:GetMouse()
m.Icon = 'http://www.roblox.com/asset/?id=7213486631'--replaces mouse icon
local character = player.Character or player.CharacterAdded:wait()
local human = character.Humanoid
local humanoidpart = character.HumanoidRootPart
local head = character:WaitForChild('Head')
local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0
local resetPos1 = Vector3.new(0,0,0)
local resetPos2 = Vector3.new(0,0,0)
local running = true
local freemouse = false
local defFOV = FieldOfView
input.InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
end
end)
input.InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
end
end)
local function began()
runService.RenderStepped:connect(function()
if game.ReplicatedStorage.InRound.Value == true then
walkspeeds.enabled = true
if running then
updatechar()
CamPos = CamPos + (TargetCamPos - CamPos) *0.28
AngleX = AngleX + (TargetAngleX - AngleX) *0.35
local dist = TargetAngleY - AngleY
dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
AngleY = (AngleY + dist *0.35) %360
cam.CameraType = Enum.CameraType.Scriptable
cam.CoordinateFrame = CFrame.new(head.Position)
* CFrame.Angles(0,math.rad(AngleY),0)
* CFrame.Angles(math.rad(AngleX),0,0)
* HeadOffset -- offset
humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
end
if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
running = false
else
running = true
if freemouse == true then
game:GetService('UserInputService').MouseBehavior = Enum.MouseBehavior.Default
else
game:GetService('UserInputService').MouseBehavior = Enum.MouseBehavior.LockCenter
end
end
cam.FieldOfView = FieldOfView
else
walkspeeds.enabled = false
game:GetService('UserInputService').MouseBehavior = Enum.MouseBehavior.Default
showHead()
player.CameraMode = Enum.CameraMode.Classic
cam.CameraType = Enum.CameraType.Custom
end
end)
end
FP.OnClientEvent:Connect(function()
began()
end)