INTRODUCTION
This module works very simply, but it can be useful in several cases, such as simple projectiles.
I’ve seen some similar options here on the developer forum, however, they didn’t meet all my needs so I decided to make one myself.
Why use this?
This module allows you to make almost completely customizable hitboxes in addition to a different way from the conventional way of making projectiles
ACCESS
You can get the module by downloading it from Roblox Marketplace
API
NubCast.new(Params : OverlapParams, Debug : Boolean)
create a new caster where you can add an OverlapParams and set debug to true or false
NubCast:Cast(origin : Vector3, target : Vector3, size : number, segments : number, travelTime : number) -- ActiveCast
cast a new hitbox with the passed parameters
ActiveCast.Stop()
stop the current cast
ActiveCast.Finished -- RBXScriptSignal
The event is triggered when the hitbox collides with something or travel time has been exceeded
ActiveCast.Hitted -- RBXScriptSignal
The event is triggered when the hitbox collides with something. passes a table with overlap params result
EXAMPLES
Creating a new hitbox
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NubCast = require(ReplicatedStorage.NubCast)
local Overlap = OverlapParams.new()
Overlap.FilterDescendantsInstances = {}
Overlap.FilterType = Enum.RaycastFilterType.Exclude
local Caster = NubCast.new(Overlap, true)
local StartPosition = Vector3.new(0, 30, 0) -- Hitboxes Origin
local TargetPosition = Vector3.new(0, -10, 0) -- Hitboxes Target Position
local Segments = 5 -- Number of hitboxes created in a cast
local Size = 5 -- Hitbox Size
local TravelTime = 1 -- Hitbox cast time
local ActiveCast = Caster:Cast(StartPosition, TargetPosition, Size, Segments, TravelTime)
Basically creating a hitbox is very simple and if you set debug to true when creating the hitbox you will be able to view it
Adding a projectile
First let’s create a folder in the workspace so the hitbox doesn’t detect the projectiles
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NubCast = require(ReplicatedStorage.NubCast)
local Overlap = OverlapParams.new()
Overlap.FilterDescendantsInstances = {workspace.Projectiles}
Overlap.FilterType = Enum.RaycastFilterType.Exclude
local Caster = NubCast.new(Overlap, true)
local StartPosition = Vector3.new(0, 30, 0) -- Hitboxes Origin
local TargetPosition = Vector3.new(0, -10, 0) -- Hitboxes Target Position
local Segments = 10 -- Number of hitboxes created in a cast
local Size = 5 -- Hitbox Size
local TravelTime = 1 -- Hitbox cast time
local Projectile = Instance.new("Part")
Projectile.Size = Vector3.one * 2
Projectile.Anchored = true
Projectile.Position = StartPosition
Projectile.Shape = "Ball"
Projectile.Color = Color3.fromRGB(88, 88, 88)
Projectile.Material = Enum.Material.Metal
Projectile.Parent = workspace.Projectiles
local TravelTween = game.TweenService:Create(
Projectile,
TweenInfo.new(TravelTime, Enum.EasingStyle.Linear),
{Position = TargetPosition}
)
TravelTween:Play()
local ActiveCast = Caster:Cast(StartPosition, TargetPosition, Size, Segments, TravelTime)
ActiveCast.Hitted:Connect(function()
TravelTween:Pause()
end)
ActiveCast.Finished:Connect(function()
Projectile:Destroy()
end)
Adding a projectile is very simple, you just need to create it and make it move with interpolation or some other method.
Just ensuring that it will pause when it hits a target to ensure that the projectile will not continue moving.
TIPS
It is recommended not to move projectiles on the server.
The module is not recommended for EVERY case as there may be some inaccuracy or loss of memory.