Whats up guys,
Ive been working on this module for a few days, wasnt too hard to make. I needed a module like this, and I thought I’d just make a full blown open source one.
Why Use Sightline?
Instead of a single raycast to a target’s center, Sightline uses a more robust approach. It checks an object’s corners and center, and can even be configured to see through semi-transparent parts. It’s all about making visibility feel like it belongs in a 3D world.
The goal is to give developers the tools for:
- Smarter AI: Create enemies that have a more realistic line of sight.
- Better Stealth Gameplay: Make hiding and cover mechanics that are fair and intuitive.
- Accurate UI: Build indicators that know when a target is actually visible vs just on screen.
- Polished Aim-Assist: Design systems that can differentiate between an exposed target and one behind cover.
- Smooth Transitions: Easily create transitions for characters or scenes without breaking immersion.
Features
The module is packed with over 40 functions, but here are the highlights:
- Core Visibility:
IsVisible(),IsFullyVisible(), andIsPartiallyVisible()give you detailed information about how much of an object is actually in view and unobstructed. - Line of Sight: A simple
LineOfSight()check that’s more configurable than a basic raycast. - Screen and Spatial Utils: A huge collection of helper functions like
IsOnScreen(),GetScreenPosition(),GetDistanceSquared(),SortByDistance(), andGetObscuredPercentage(). - Configurable: You can easily change the “ray depth” (how many transparent parts it can see through) and the transparency threshold. You can also create a global ignore list.
- Modular and Clean: The new version is completely reorganized into sub-modules for Core, Utils, Debug, and Config, making it super easy to read and modify.
The module has 40 functions, but you most likely won’t use all of them. Some of them are very specific functions, but the one function I truly reccomend is IsVisible(). It’s honestly so helpful and can be used in almost every genre of games.
Example
Here’s how you can make an NPC smoothly disappear after a conversation, but only once they’re out of sight:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Sightline = require(ReplicatedStorage.Sightline)
-- Let's assume you have an NPC model in the workspace
local npc = workspace:WaitForChild("friendJohn")
-- This function simulates the end of a dialogue scene
local function startDisappearSequence()
print("John: 'Wanna see a cool magic trick?'")
task.wait(2) -- Give the user time to react
local visibilityCheckConnection = RunService.RenderStepped:Connect(function()
-- We check against the NPC's main part, like the HumanoidRootPart
if not npc.PrimaryPart then
visibilityCheckConnection:Disconnect()
return
end
-- If the character is no longer visible on screen...
if not Sightline.IsVisible(npc.PrimaryPart) then
print("John disappeared.")
npc:Destroy() -- Make them disappear
visibilityCheckConnection:Disconnect()
end
end)
end
-- Start the sequence
startDisappearSequence()
Considerations
This module performs many checks to get its accuracy. It’s fast, but you should still be smart about how you use it.
I was mainly inspired by modern games where the world feels solid and the AI feels fair. I wanted to bring a tool like that to Roblox developers in a way that is both powerful and easy to use.
The entire module is fully typed with Luaus export type, so you’ll get great autocompletion and error checking if you use it. Reccomended by @reeeesaur. Never really made a system like this before so thank you.
Heres the download fam <3:
[Download]
Let me know what you think! If you have any questions, ideas, or find any bugs, please reply to this topic. I’d be happy to help.
How would you rate this module?
- AMAZING, just what I needed!
- decently useful.
- idk
- I would never use this.