I am scripting a “free move” camera system, like the one in Roblox Studio.
The issue starts when the player moves the camera LookVector. The camera FOV appears to be increasing when looking up. Checking the actual FOV shows that the FOV isn’t actually changing. Heres a video:
robloxapp-20200319-1855109.wmv (3.1 MB)
(sorry if it’s laggy, my computer sucks )
I’m completely stumped as to what causes this and there aren’t any threads discussing this. If you’re curious, here’s the code:
--Variables
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
--Camera settings
local CameraObject = {
Angle = Vector2.new(0, 0),
Subject = Vector3.new(0, 0, 0),
Zoom = 2,
Speed = .5,
Y_Limit = 75
}
--Mix
local Mix = require(game.ReplicatedStorage.Components.MixPlus)
local MixObj = Mix:GetSublibrary("RbxObj")
UserInputService.InputChanged:Connect(function(Input, success)
--Move camera
if Input.UserInputType == Enum.UserInputType.MouseMovement then
--Get mouse delta
local Delta = UserInputService:GetMouseDelta()
--Prevent spam
if Delta ~= Vector2.new(0, 0) then
Pan(-Delta.X*.5, Delta.Y*.5)
end
end
end)
--Start mouse lock
UserInputService.InputBegan:Connect(function(Input, success)
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end
end)
--Stop mouse lock
UserInputService.InputEnded:Connect(function(Input, success)
if Input.UserInputType == Enum.UserInputType.MouseButton2 then
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end)
--Pans camera by X and Y angles
function Pan(X, Y)
--Adjust speed
local X = X*CameraObject.Speed
local Y = Y*CameraObject.Speed or 0
--Change angle
CameraObject.Angle = Vector2.new(CameraObject.Angle.X + X, CameraObject.Angle.Y + Y)
--Y angle limit
if math.abs(CameraObject.Angle.Y) > CameraObject.Y_Limit then
CameraObject.Angle = Vector2.new(CameraObject.Angle.X, CameraObject.Y_Limit * math.sign(CameraObject.Angle.Y))
end
--Convert the angles to CFrame
local Vector = AnglesToUnit(CameraObject.Angle.X, CameraObject.Angle.Y)
local CameraCFrame = MixObj:CreateCFrame(CameraObject.Subject - Vector*CameraObject.Zoom, Vector)
--Set CFrame
Camera.CFrame = CameraCFrame
end
--Convert angles into unit sphere
function AnglesToUnit(Angle1, Angle2)
--Gets the Angle2 distortion value
local Angle2_Distortion = math.cos(math.rad(Angle2))
--Gets the coordinates for the unit sphere
local X = math.cos(math.rad(Angle1)) * Angle2_Distortion
local Y = math.sin(math.rad(Angle2))
local Z = math.sin(math.rad(Angle1)) * Angle2_Distortion
return Vector3.new(X, Y, Z)
end
Player.CharacterAdded:Connect(function()
wait() --Idk why this needs to be here, but it does so camera doesn't break
--Initiates camera
Camera.CameraType = Enum.CameraType.Scriptable
Player.Character.Parent = nil
end)