Introduction
SimpleRay is a raycasting module to make raycasting easier. It has more features such as custom filters, max ray instances etc.
For more information, visit the GitHub repository or documentation.
Features
- Normal raycasting features
- Multiple instances in result
- Dynamic filters
- Ignore parts with CanCollide off
- Ignore parts which have their transparency between a range of numbers
- Create a custom instance filter to fit your needs
- Easily visualize rays
Why use SimpleRay ?
Raycasting is sometimes tedious, but SimpleRay makes this process easier!
Here’s an example of normal raycasting
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {
workspace.Part2
}
local startPoint = Vector3.new(0, 0, 0)
local endPoint = Vector3.new(0, 10, 0)
local raycastResult = workspace:Raycast(startPoint, (endPoint-startPoint).Unit * 100, raycastParams)
if raycastResult then
...
end
But why use that when you can use SimpleRay ? It only requires one expression!
local SimpleRay = require(game.ReplicatedStorage.SimpleRay)
local startPoint = Vector3.new(0, 0, 0)
local endPoint = Vector.new(0, 10, 0)
local maxRayInstances = 2
local result = SimpleRay.new({
Origin = startPoint,
Direction = (endPoint-startPoint).Unit * 100,
Params = {
IgnoreWater = true,
Blacklist = {
workspace.Part2
}
},
MaxParts = maxRayInstances,
IgnoreCollideOffParts = true,
IgnoreTransparency = NumberRange.new(0.1, 1),
CustomFilter = function(inst: Instance)
return inst.Name ~= "Debug"
end,
Visualize = true
}):GetResult()
if result then
print(result)
end
--[[
Example Output:
{
Distance = 50,
Position = Vector3.new(12, 0, 37),
Normal = Vector3.new(0, 1, 0),
Instances = {
{
["Instance"] = workspace.Part,
["Material"] = Enum.Material.Plastic,
["Normal"] = Vector3.new(0, 0, 1),
["Position"] = Vector3.new(-2, 5, -17)
},
{
Instance = workspace.Baseplate,
Material = Enum.Material.Plastic,
Normal = Vector3.new(0, 1, 0),
Position = Vector3.new(12, 0, 37)
}
}
}
]]
All the options are stored in one dictionary, and the result can hold multiple Instances.
On top of that, the options can have dynamic custom filters!
Installation
Method 1: Model File (Roblox Studio)
Download the rbxm
model file attached to the latest release from the GitHub releases page.
Insert the model somewhere in your game like ReplicatedStorage
Method 2: Filesystem
If you are using Rojo or any similar plugin, you can copy the src
file into your codebase and rename it to SimpleRay.