Hi all, I have this weird issue where I have a script that makes my mouse follow the camera, but with a restricted version of a clamp. The issue is - when I move my cursor in the region (about 20% from the left of the screen & middle) - this odd flicker occurs and offset issue. When I have my mouse resting in the specific region the camera flickers very extremely, and when I move my mouse in the region left of the flicker region, there’s an offset compared to the normal region. When my mouse is moving in the normal region the clamp behaviour works perfectly as normal. Can anyone provide me with any help? Thanks.
function FunctionLibrary.Mouse_Cast(Multiplier,Listing,Instance,Vector,...)
if not Service['RunService']:IsClient() then
return nil
end
if not Listing then
Listing = Enum.RaycastFilterType.Exclude
end
local Camera = workspace.CurrentCamera
local Mouse_Location do
if (not Service['UserInputService'].KeyboardEnabled) and Service['UserInputService'].TouchEnabled and (not Service['UserInputService'].MouseEnabled) then
local ViewportSize = Camera.ViewportSize
Mouse_Location = Vector2.new(ViewportSize.X * 0.575, ViewportSize.Y * 0.5)
else
Mouse_Location = Service['UserInputService']:GetMouseLocation()
end
end
local Mouse_Delta = Camera:ViewportPointToRay(Mouse_Location.X, Mouse_Location.Y)
local Raycast_Parameter = RaycastParams.new() do
Raycast_Parameter.FilterType = Listing
for i,v in pairs({...}) do
Raycast_Parameter:AddToFilter(v)
end
end
local Raycast = workspace:Raycast(Mouse_Delta.Origin, Mouse_Delta.Direction * 10000, Raycast_Parameter)
if not Raycast then
if Vector then
return Mouse_Delta.Origin + (
Mouse_Delta.Direction * (Multiplier or 75)
)
end
else
if Instance and Raycast.Instance then
return Raycast.Instance
else
return Raycast.Position
end
end
end
local camera = Client.Camera
local loadingcframe = script:WaitForChild("loading_cframe",1)
pcall(function()
Client.Player:RequestStreamAroundAsync(loadingcframe.Position,10)
end)
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 60
camera.CFrame = loadingcframe.CFrame
local clamp = 200
local connection
local raycastPart = Instance.new("Part")
raycastPart.Size = Vector3.new(100,100,0.001)
raycastPart.Anchored = true
raycastPart.Transparency = 1
raycastPart.Parent = workspace
raycastPart.CFrame = loadingcframe.CFrame
raycastPart.Position += raycastPart.CFrame.LookVector * 10
task.wait(1)
connection = Library.Service.RunService.RenderStepped:Connect(function(dT)
if not connection then
return
end
if Client.Player.Character then
return
end
local x,y,z = CFrame.new(loadingcframe.Position, functions.Mouse_Cast(100, Enum.RaycastFilterType.Include,nil,nil,raycastPart)):ToOrientation()
local results = {}
for axis,value in {['x'] = x, ['y'] = y, ['z'] = z} do
results[axis] = math.rad(value)
results[axis] = math.clamp(results[axis], -clamp, clamp)
end
local tC = loadingcframe.CFrame * CFrame.Angles(results.x,results.y,results.z)
camera.CFrame = tC
end)
The raycastPart which is the only part whitelisted in the raycast operation.
