Let's say I want a model to lack collision if it's off-screen, but I want cancollide to be on if it's on-screen, how would I accomplish this?
First, you would use WorldToScreenPoint to tell if a part's center was on the screen:
local function IsOnScreen(Part) local Point, Bool = Camera:WorldToScreenPoint(Part.Position) return Bool end
However, this will only tell you if the part is on the screen. To tell if it is not hidden behind an object, you can use raycasting from the camera to the part to detect any other parts that may be in the way:
local function IsVisible(Part) local R = Ray.new(Camera.CFrame.p, (Part.Position - Camera.CFrame.p).unit * 999) local DetectedPart = workspace:FindPartOnRay(R,Part) return not not DetectedPart end
This example would return true if there was a part in the way of the camera and the part, by casting a ray from the camera to the part.
You would then regularly iterate through the parts you want to check and can apply these functions as outlines to detect if they are visible.