How do you make hitboxes with priority preferences?

So I’ve seen few things that Forsaken have done and in their logs I’ve noticed they’ve moved things like guest’s hitbox priority over regular survivors, and structures such as a turret over players, thats sorta what im talking about right now

So how do I make a hitbox target specific catagories before targetting others?

Example: Enemy player hits an area consisting of a barrier and a player, and the hitbox is more likely to hit the barrier, then the enemy has to attack again to hit the player (once the barrier gets destroyed)

1 Like

Tell me if I used the wrong tag because I didnt know which to use…

assuming most games use overlapparams and GetPartBoundsInBox or GetPartBoundsInRadius, if you want to prioritize certain models you can either use table.sort or a loop to check for tags/properties.
an example of a table.sort would be:

local Parts = workspace:GetPartBoundsInRadius(Position, Radius, OLP) -- assuming this returns player character body parts or the barrier part
local ReturnedDict = {}
local ReturnedList = {}
for _,Part in next, Parts do
	local Parent = Part.Parent
	if ReturnedDict[Parent] == true then continue end
    ReturnedDict[Parent] = true
	table.insert(ReturnedList,Parent)
end
table.sort(ReturnedList,function(Model1,Model2)
	local Tag1,Tag2 = Model1:HasTag("Barrier"),Model2:HasTag("Barrier")
	return Tag1 == true and Tag2 == false 	
end)
return ReturnedList

in this case, i sort the table after the parents have been gathered to place the barrier objects in the front (first table position). most of the time, this is convenient but could potentially be slower then the table scan i do below.

an example of a table scan would be:

local Parts = workspace:GetPartBoundsInRadius(Position, Radius, OLP) -- assuming this returns player character body parts or the barrier part
local ReturnedDict = {}
local ReturnedList = {}
local PriorityList = {}
for _,Part in next, Parts do
	local Parent = Part.Parent
	if ReturnedDict[Parent] == true then continue end
	ReturnedDict[Parent] = true
	local Barrier = Parent:HasTag("Barrier")
	if Barrier == true then
		table.insert(PriorityList,Parent)
	else
		table.insert(ReturnedList,Parent)
	end
end
table.move(ReturnedList,1,#ReturnedList,#PriorityList+1,PriorityList)
return PriorityList

in this example, i am directly checking for the barrier tag in the parts loop and putting them in a priority list. after everything has been iterated through, i move the non-priority models to the end of the priority list and return the priority list so any barrier parts will always be hit first.

the methods you use will change depending on your code base, but using a tags system combined with proper overlapparameter usage will make your code much faster and easy to implement

Thanks a lot! I’ll be sure to take a look into this later.

1 Like