How to make a hitbox of all front Vectors for raycast

hello im amaro, im trying to make a hitbox, much like the tsb, by myself, but i dont use raycast that much, and i think raycast params are very good, now i notice that i have a raycast function that just go throw the CFrame.LookVector, and multiply by a number as the direction, now is there any way to achive something like this?
(drawing example):

raycast hitbox

(sorry for the quality of the image)

video for more example of more what im looking on:

for you asking, im not trying to copy tsb, i really want to make a really good hitbox like my dear beloved game tsb, cuz i really like the game and i get a lot of inspirations from tsb and other games, please help me to make a good raycast hitbox, or something that is looks like the tsb hitbox cuz is too good, so i want to try out.

and plus raycast has been good for me rn, and i have a fully script module with the mayority of hitbox methods know to man, so yeah, i really like were this si going

I’ve suggested this: WorldRoot | Documentation - Roblox Creator Hub to somebody, who was doing almost the same. You just set the radius to wanted angle and boom, you should have something like you’ve drawn for reference.

You could do this, and as person before me mentioned you just iterate over angles, or you could use shapecasting specifically blockcast.

This would greatly reduce raycasts from multiple to one, although it wouldnt be in half circle.

If you really wanted to check half circle infront of character, you could use spherecast, and use :Dot product to check whether caught player is infront or not.

1 Like

Yeah, I was referring to spherecast, but the link seems to go streight to shapeCast section.

1 Like

by that, i think i like it, but im confused about something, how i configure the radius???

yea, literaly trying to see how to use spherecast, shows more shapecast stuff

Scroll little down the shapecast, and you should find the spherecast. I’m sure there’s detailed tutorial on how to use spherecast in devforum.

I’m pretty sure TSB doesn’t use raycasting for that, but instead uses :GetPartBoundsInBox (:GetPartBoundsInRadius for spherical hitboxes) . I’d suggest reading the documentation for it and trying it out to see if it’s what you are looking for.

Documentation: WorldRoot | Documentation - Roblox Creator Hub

This is what I did (Character is Attacking Player Character)

local CharacterCF = Character:GetPivot()
				local CharacterSize = Character:GetExtentsSize()
				
				local Params = OverlapParams.new()

				Params.FilterType = Enum.RaycastFilterType.Exclude
				Params.FilterDescendantsInstances = {Character}
				
				--[[
				local hitbox = Instance.new("Part")
				hitbox.CanCollide = false
				hitbox.Anchored = true
				hitbox.CFrame = Character:GetPivot() + Character:GetPivot().LookVector * Character:GetModelSize().Z
				hitbox.Size = Character:GetExtentsSize()
				
				hitbox.Parent = workspace
				]]

				local Cast = workspace:GetPartBoundsInBox(CharacterCF + CharacterCF.LookVector * CharacterSize.Z, CharacterSize, Params)

				if Cast then
					for _, part in Cast do
						local Character = part:FindFirstAncestorWhichIsA("Model")
						local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")

						if Humanoid then
							Humanoid.Health -= M1.Damage
							break
						end
					end
				end

well, in resume, every respond i did like. lol, i make some examples on client and make a vizualice, ig i have to use more “run service” on my hitbox system with multiple methods, cuz is more accurate instead of a for loop

getpartinbox (one that i used, but im wanna updated it to this version):

local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()
local Character = player.Character
local humanoidroot = Character:FindFirstChild("HumanoidRootPart")

local function se()
	local CharacterCF = humanoidroot.CFrame
	local CharacterSize = humanoidroot.Size
	
	local Params = OverlapParams.new()

	Params.FilterType = Enum.RaycastFilterType.Exclude
	Params.FilterDescendantsInstances = {Character}
	
	local hitbox = Instance.new("Part")
	hitbox.CanCollide = false
	hitbox.Transparency = 0.5
	hitbox.Color = Color3.new(1,0,0)
	hitbox.Anchored = true
	hitbox.CFrame = CharacterCF + CharacterCF.LookVector * CharacterSize.Z * 6
	hitbox.Size = CharacterSize
	hitbox.Parent = workspace
	
	game:GetService("Debris"):AddItem(hitbox, .2)
	
	local Cast = workspace:GetPartBoundsInBox(CharacterCF + CharacterCF.LookVector * CharacterSize.Z * 6, CharacterSize, Params)

	if Cast then
		for _, part in Cast do
			local Character = part:FindFirstAncestorWhichIsA("Model")
			local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")

			if Humanoid then
				print("lol")
				hitbox:Destroy()
				break
			end
		end
	end
end

game:GetService("RunService").RenderStepped:Connect(se)

spherecast (the one that i like less, cuz if i get close is very weird):

local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()

local function createRayVisualization(startPos, endPos)
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = false
	part.Material = Enum.Material.Neon
	part.Color = Color3.new(1, 0, 0)
	part.Size = Vector3.new(0.1, 0.1, (endPos - startPos).Magnitude)
	part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
	part.Parent = workspace.Effects
	print(part.Size.Z)
	game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end
local function raycastc(origin: Vector3, radius: number, direction: Vector3, distance: number, filterType, filterTable)
	local raycastParameters = RaycastParams.new()
	raycastParameters.FilterType = filterType
	raycastParameters.FilterDescendantsInstances = filterTable
	raycastParameters.IgnoreWater = true

	local raycastResult = workspace:Spherecast(origin, radius, direction * distance, raycastParameters)


	if raycastResult ~= nil then		
		return raycastResult	
	else		
		return "Nothing was hit"		
	end
end
local distance = 5

local alreadyhit = {}

local function monkey()
	local origin = player.Character.HumanoidRootPart.Position
	local direction = player.Character.HumanoidRootPart.CFrame.LookVector
	local raycastResult = raycastc(
		origin,
		5,
		direction,
		distance,
		Enum.RaycastFilterType.Exclude,
		{
			workspace.Effects, 
			workspace.Map, 
			player.Character
		}
	)
	local rac = raycastResult.Instance
	if raycastResult ~= "Nothing was hit" then
		if rac.Parent:IsA("Workspace") then return end
		if rac.Parent:IsA("Accessory") or rac.Parent:IsA("Hat") or rac.Parent:IsA("BasePart") then
			rac = rac.Parent
		end
		createRayVisualization(origin, raycastResult.Position)
		if rac.Parent.Humanoid then
			if not alreadyhit[rac.Parent.Humanoid] then
				print("monkey")
			end
		end
	end
end

game:GetService("RunService").RenderStepped:Connect(monkey)

shapecast (this one i really really like):

local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()
local root = player.Character.HumanoidRootPart

local function createRayVisualization(startPos, endPos)
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = false
	part.Material = Enum.Material.Neon
	part.Color = Color3.new(1, 0, 0)
	part.Size = Vector3.new(0.1, 0.1, (endPos - startPos).Magnitude)
	part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
	part.Parent = workspace.Effects
	print(part.Size.Z)
	game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end
-- Function to visualize ShapeCast
local function createShapeCastVisualization(startPos, endPos, radius)
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = false
	part.Material = Enum.Material.Neon
	part.Color = Color3.new(0, 1, 0)
	part.Size = Vector3.new(radius * 2, radius * 2, (endPos - startPos).Magnitude)
	part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
	part.Parent = workspace.Effects
	game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end

local radius = 2

local function raycastc(origin: Vector3, direction, distance, filterType, filterTable)
	local raycastParameters = RaycastParams.new()
	raycastParameters.FilterType = filterType
	raycastParameters.FilterDescendantsInstances = filterTable
	raycastParameters.IgnoreWater = true

	local raycastResult = workspace:Shapecast(origin, direction * distance, raycastParameters)

	if raycastResult ~= nil then		
		return raycastResult	
	else		
		return "Nothing was hit"		
	end
end
local distance = 10

local alreadyhit = {}

local part = Instance.new("Part",workspace.Effects)
part.Size = Vector3.new(9,5,0)
part.Color = Color3.new(0, 0, 1)
part.Name = player.Name.. "Hitbox"
part.Transparency = 0.5
part.CanCollide = false
part.Anchored = false
part.Massless = true

local weld = Instance.new("Motor6D")
weld.Parent = root
weld.Part0 = root
weld.Part1 = part
weld.Name = "joinhitbox"

local function monkey()

	local origin = part
	local root_cframe = origin.CFrame
	local root_size = origin.Size
	local direction = root_cframe.LookVector
	local raycastResult = raycastc(
		origin,
		direction,
		distance,
		Enum.RaycastFilterType.Exclude,
		{
			workspace.Effects, 
			workspace.Map, 
			player.Character
		}
	)
	local rac = raycastResult.Instance
	if raycastResult ~= "Nothing was hit" then
		if rac.Parent:IsA("Workspace") then return end
		if rac.Parent:IsA("Accessory") or rac.Parent:IsA("Hat") or rac.Parent:IsA("BasePart") then
			rac = rac.Parent
		end
		createShapeCastVisualization(origin.Position, raycastResult.Position, radius)
		if rac.Parent.Humanoid then
			if not alreadyhit[rac.Parent.Humanoid] then
				print("monkey")
			end
		end
	end
end

game:GetService("RunService").RenderStepped:Connect(monkey)

for any modifications, or make it better it could be really nice, sorry for being late, too busy in life

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.