Hey developers.
I’m not too sure if a module like this has been created so I went ahead and made one anyway.
Introducing Radius.
This module is to help developers detect when players enter a specific magnitude of a BasePart, detects obstructions and comes with 2 lightweight functions you can use whenever
I myself find it quite useful and thought I’d share it with ya’ll.
Example Usage
local Radius = require(game.ReplicatedStorage.Radius)
local RadiusObject = Radius.new({
Part = Part, --The base part you're wanting to look out for.
MaximumRadius = 30, --The radius in which events are fired.
Obstructions = true, --This enables a system where itll only detect players in the radius when there's no parts blocking or obstructing them.
Log = true, --Enables warning logs (debugging)
})
RadiusObject:Initialise() --Enables the events.
local PlayerMagnitude = RadiusObject:GetPlayerRadius(Player: Player)
-- Returns (number | nil)
-- The distance any player is away from the part.
local Obstruction = RadiusObject:GetObstruction(Player: Player, Blacklist: {[number]: any})
-- Returns (RaycastResult | nil)
-- Use this to see if theres a wall or something blocking the radius of the player.
-- The second parameter is to filter out specific parts from the raycast. (not required)
RadiusObject.Entered:Connect(function(Player: Player)
print(Player.Name.." entered.")
end)
RadiusObject.Exited:Connect(function(Player: Player)
print(Player.Name.." exited.")
end)
RadiusObject:Destroy() --Stops all resource usage.
Why not use Region3 or ZonePlus
These modules are very good, and I couldn’t recommend using them more but sometimes developers find it easier to use Magnitude for a different number of things, whether it be AI, general effects or whatever you decide to create which is why in my personal opinion I believe this to be a useful module.
If you have any questions, reply on the back of this thread and I’ll be able to help when I can.
Get it here.