Raycast Projectile Module V2! (kinda)

Hey! Welcome to my post on my brand-spankin’ new raycast projectile module! (kinda)
The reason its “Kinda” a new raycast projectile module is because… well… it doesnt use raycasting, rather getPartsBoundInBox, but because my last post used Raycasting, im going to call it a raycast projectile module.

This new and improved module is much simpler and more optimized, with a more reliable hit-detection method. It also supports Bezier projectiles (quadratic and cubic movement).

(Current) Features

Linear projectile
Cubic & Quadratic projectiles
Far more reliable hit detection method
Returns all the hit parts and hit position
Automatically waits for it to hit before continuing
Works in 2D and 3D environments
Automatic projectile despawn
Returns ALL objects that where hit (not just one)
Detects objects of any size
Hitbox size is the projectile size

Code Examples
BEZIRE EXAMPLE :

local mod = require(game.ServerScriptService.DusksProjectileModule)
task.spawn(function()
	local p = script.Parent.Position
	local hit = mod.BezierProjectile({p, p+Vector3.new(0,50,-150), p+Vector3.new(0,25,150)}, "quadratic", {script.Parent}, script.Parent, 50)
	
	if hit then --makes sure its not nil; module automatically waits until it hits before continuing
		local hitPos = hit["HitPos"]
		local objHit = hit["HitTable"][1] --can change 1 to any number, but 1 is recommended
	end
end)


LINEAR EXAMPLE : 

local mod = require(game.ServerScriptService.DusksProjectileModule)
task.spawn(function()
	local p = script.Parent.Position
	local hit = mod.LinearProjectile(p, script.Parent.CFrame.LookVector*9999,script.Parent, {script.Parent}, 50, 60)

	if hit then
		local hitPos = hit["HitPos"]
		local objHit = hit["HitTable"][1] --can change 1 to any number, but 1 is recommended
	end
end)
Arguments
module.LinearProjectile -> 
	pointA = starting vector of projectile
	direction = direction projectile moves in (projectile.CFrame.LookVector)
	projectile = the object being shot
	blacklist = table of ignored objects
	speed = how fast the projectile moves
	despawnTime = how many seconds before projectile automatically removes its self
	returns {
		["HitPos"] = position where projectile hit something
		["HitTable"] = table of objects that where hit (can be more than one, I recommend using the first one)
	}

module.BezierProjectile ->
	bezireArgs = table of points ({p0,p1,p2,p3}) leave p3 blank if quadratic
	bezierType = what type of bezier ("cubic" or "quadratic")
	blacklist = table of ignored objec
	projectile = the object being shot
	speed = how fast the projectile moves
	returns {
		["HitPos"] = position where projectile hit something
		["HitTable"] = table of objects that where hit (can be more than one, I recommend using the first one)
	}

Video example of the linear and bezier projectiles : Projectile Module Examples
(ik the video is bad)

Thanks and see’ya later!
Get the module here : Dusks Projectile Module - Roblox

6 Likes

I was using your module when I found that a projectile sometimes missed a target entirely. The problem was that the script was only checking if the the first item in objectsInBox had collision, and as some limbs don’t have collision, it might phase through a target if objectsInBox[1] was always a non-colliding part.

1 Like

I could see how this could be an issue. It ignores noncolliding parts because some games might have invisible/non-interactable objects that shouldnt be hit (like a hitbox visualizer, interaction button, ect). In the future, I could see myself adding a collision parameter.

I’m pretty sure setting a part’s CanQuery to false will cause the part to be ignored by just about any detection method, like :GetBoundsInBox.

1 Like

How do I go about making a hit function?

Why did you use get parts in bound box, rather than a shape cast?