Introducing silly cats manages hitboxes V2.2! Create Magnitude Hitbox With Ease!

scripts using v1.0 and v1.1 is not compatible to v2.0

MIT LISCENE

Silly Cat Manages Hitboxes

image
also no I didn’t draw this I just think it’s silly

Github

Source Code

Example Place

Download

Roblox Model

Introduction

Hello! I’ve created a roblox hitbox manager that uses magnitude to detect humanoid characters. This was created October 7 2022, Last updated 1/14/2023. This module uses module uses Janitor and Stravant’s Good Signal. The reason I made this module is because I couldn’t find any magnitude hitbox modules and I really wanted to use a magnitude hitbox system, so I decided to make one myself. My intention of this module is to be mainly used in fighting games and to be easy to modify and add onto to suit your needs.

A basic sword tool using this module

example gif

What features does this include?

This is what I would like to think is pretty minimal. This module is accurate and is easy to use and understand. It contains a ‘Characters’ table which you could add humanoid characters that you want the hitbox to check if they’re in range, a way to visualize the hitbox, and a way to make the hitbox not scan certain characters. You can toggle the hitbox visuals by editing the module. As well toggle if players are automatically added or not.

What are the limitations?

Only checks characters that are added to the ‘Characters’ table through the .AddCharacter() function. Therefore you must manually add NPCS (players could be automatically added through the module, you can turn this off by going into the settings)

‘Hit’ only hits a character once unless you modify the ‘IsImmune’ property of a hitbox. I’ll also talk about how you could go about implementing a tick-based hitbox if you really want a tick-based hitbox system.

This module is not set up as object oriented!!

Performance could tank if you have too many hitboxes or humanoid characters in ‘Characters’. I’ll discuss a possible solution to this. Though I believe you shouldn’t really worry about this as I believe most hitboxes in fighting games usually last around 0.1 - 2 seconds. For having too many characters you could implement an octree. Will talk about this later

API

Click here to open the API!

I apologize for the half-baked documentation.

Functions

Void HitboxManager.AddCharacter(Character: Character Model)

Adds a character with a humanoid and a root part to the hitbox manager. Will automatically clean up when the character is dead or voided.

local NPCS = workspace.NPCS --path to your npcs 
for _,NPC in pairs(workspace.NPCS:GetChildren()) do -- this is how you add npcs who are in a folder.
	hitboxManager.AddCharacter(NPC) --Now the NPC is added it'll now be able to be detected by hitboxes!
end

Hitbox Dictonary HitboxManager.new(hitboxPart: BasePart, range: number, duration: number, immune: Character Models)

Creates a new hitbox.

  • hitboxPart: is where the magnitude hitbox will project and scan around
  • range: is the range of the magnitude
  • duration: how long the hitbox last in seconds
  • immune: **humanoid character(s) that is immune to the hitbox. The hitbox manager won’t scan these characters. This can be a table with characters or just a single character that’s not in a table. This is OPTIONAL
  • Return the dictionary of the hitbox where you can send it in HitboxManager.Destroy( dictionary) to prematurely stop the hitbox.
local newHitbox = hitboxManager.new(Handle, 3, 1, SingleCharacterThatsNotaTable) --creates a new magnitude hitbox that will scan around Handle with a range of 3 and will last 1 second. Variable Character will be ignored.
-- OR
local newHitbox = hitboxManager.new(Handle, 3, 1, {Character1, Character2, Character3}) -- Put multiple character that's immune by inserting them in a table.

Void HitboxManager.Destroy( Hitbox Dictonary )

Prematurely stops the hitbox and destroying it. Therefore cleaning up signals and gets garbage the collected next frame. Also voiding itself.

local newHitbox = hitboxManager.new(Handle, 3, 1, Character) --creates a new magnitude hitbox that will scan around Handle with a range of 3 and will last 1 second. Variable Character will be ignored.
task.wait(.5)
hitboxManager.Destroy() --force destroys the hitbox in .5 seconds. This is before the silly cat destroys the hitbox.

Events

RBXScriptSignal .Hit(Humanoid)

Fire when a humanoid character is in range of the hitbox. This will return the humanoid of the humanoid Character.

local newHitbox = hitboxManager.new(Handle, 3, 1, Character) --creates a new magnitude hitbox that will scan around Handle with a range of 3 and will last 1 second. Variable Character will be ignored.
newHitbox.Hit:Connect(function(enemyHumanoid) --any humanoid who's in the hitbox radius will take 15 damage.
  enemyHumanoid:TakeDamage(15)
end)

Properties

Table .IsImmune

Humanoid characters that were already hit by the hitbox, therefore immune to the hitbox. You can add multiple humanoid characters into this hitbox to make them immune from the hitbox. Great for removing friendly fire in games.

local newHitbox = hitboxManager.new(Handle, 3, 1) --creates a new magnitude hitbox that will scan around Handle with a range of 3 and will last 1 second. There's no character's who's immune yet.
newHitbox.IsImmune = {
  Character,
  Character1,
  Character2,
  ect.
}--These guys in the '.IsImmune' table won't take 15 damage if they're in the hitbox!
newHitbox.Hit:Connect(function(enemyHumanoid) --any humanoid who's in the hitbox radius will take 15 damage.
  enemyHumanoid:TakeDamage(15)
end)

number .Range

The range/size of the hitbox. Thic can be changed anytime while the hitbox is active (before the duration is over or before it gets destroyed). Do note that visuals doesn’t update when the range changes.

local newHitbox = hitboxManager.new(Handle,3,1,Character) --creates a new magnitude hitbox that will scan around Handle with a range of 3 and will last 1 second. Variable Character will be ignored.
newHitbox.Hit:Connect(function(enemyHumanoid) --any humanoid who's in the hitbox radius will take 15 damage.
  enemyHumanoid:TakeDamage(15)
end)
newHitbox.Range = 15 --changes the range from 3 to 15!!

Possible solutions to problems

Click here for possible solutions to problems
  • I may implement these ideas and put the files on github in the future. I apologize if you guys were looking for some scripts that you could add on. Sadly you would need to add these yourself unless I decide to implement these myself (I’m updating this module

Performance increase:

You could make usage with parallel luau and run the :ConnectParallel heartbeat method every time you’ve created a hitbox. So instead of having a heartbeat method which iterates through every hitbox which iterates through every character, you’ll now just have a hitbox iterating through each character.

This however still has some issues. If you have too many characters then your performance can still tank. My suggestion to solve this is by using an **octree (grid chunk system) to see if a character is worth checking. i.e if a character is 1000 studs away the module wouldn’t check it but if a humanoid is around 0-200 studs away it might actually be worth checking to see if the character gets hit by the hitbox. I’m sure there’s a few modules that can help achieve this octree system.

To increase performance even further, you could look into converting silly cat into a client side solution. You may be asking “Isn’t that bad because exploiters can just abuse this?” Yes and no. Exploiters wouldn’t be able to really abuse this if you check if the hitbox is really there on the server as well as a magnitude check to see if the character is really near (with a leeway of course so players with higher ping wouldn’t get a false positive). With all of this performance trick, your combat experience will be more consistent, smooth, and much more performant.

Beam type attacks

Let’s say you have an attack that’s a laser beam. If you try to utilize this module to create a hitbox for this, there would only be one hitbox and it would only be in the center of the beam attack. So if any character that’s touching the beam part but not the actual hitbox then the hitbox won’t actually detect them being hit by the hitbox. My suggestion is using attachments (like Raycast Hitbox v4) and create multiple hitboxes based on the attachments and putting all of them in one parent table. As well putting the ‘IsImmune’ property in the new parent table instead of having that property in each hitboxes (we’ll remove the ‘IsImmune’ property in the hitboxes) . Then have the hitbox checker run through if a character is in the hitboxes. If one of the hitbox detects a character then you’ll put that character in the ‘IsImmune’ table which is inside the parent table. Each hitbox that has been created based on the attachment would also check the ‘IsImmune’ property that’s in the parent table.

Tick based attacks

Let’s say you have a multi-hit attack like a barrage of slashes or punches. First, we have 1 solution for this without touching or making modifications to the module.

This is somewhat a lazy and naive solution but if you really really want to avoid getting your hands dirty and modify and add onto the module is, you could again run a loop but instead of creating a new hitbox.


local Characters = {Hi, Roblox, ThisGuy}

newHitbox = HitboxManager.new(Part, Range, Duration, Characters)

newHitbox.Hit:Connect(function(Humanoid)
  Humanoid:TakeDamage(10)
end)

for i=1,30 do
  newHitbox.IsImmune = {Characters} -- resets who has already been hit by the hitbox
  task.wait(tick duration)
end

Or you could create a new function in the hitbox to make the tick hitbox more accurate and possibly more performate. To make a new function where you add a conditional in the heartbeat connection which would clear the hitbox IsImmune except the characters that you decide that’s the user or is immuned to the hitbox. This is mainly for the sake of readability but your script styling is all preference. (Also it could be slightly faster if you implement it well)

So this is kinda like the end of this post. I’ll maybe or may not be creating solutions to said problems when I get motivated again and need these solutions (I’ll definitely be implementing an octree for a performance boost soon). V2.1 is just bug fixes and slightly better typing and that’s it. Thanks for reading, criticism is appreciated. :+1:

11 Likes

I guess we can’t compare it with raycast hitbox since it uses method of spawning part instead of attachments? I quite don’t understand for what this hitbox is exactly

1 Like

Hey! Sorry for the late response, but this module doesn’t spawn any parts to actually detect humanoid characters. The only usage of the parts that are being added is to visualize the hitbox only. (Sorry if this is explained poorly) Magnitude is the size of an imaginary sphere to check the distance two objects (I hope this is accurate). If the character is in that distance then the .Hit will fire. If not then it’ll not fire.

Some images to hopefully better help you understand what magnitude is (not the only usage):

The reason I made this module is to give people who don’t know how to make these kinds of hitboxes another option. Since some people may not like raycast hitbox. There’s many games that uses magnitude as hitboxes (not using this module) naming a few that I know uses magnitude:

A Bizzare Day

Verdant Moon

Rogue Lineage

1 Like

Version 1.1 out.

Minor changes

  • Fixed a bug where character’s are not removed when they die or get destroyed.
  • Made silly cats more optimized!

Major Changes

New function: HitboxManager:AddCharacter(character)
You’ll now need to fire this function when you want to add a character to be affected by the magnitude hitboxes now. Sorry!

What’s the difference between this and GetPartBoundsInRadius?

From my research and what I can tell, magnitude checks between the center position and what’s being checked. GetPartBoundsInRadius checks every part around the center position. Though I may be wrong.

1 Like

Isn’t that the same thing, just the default is a little more optimised?

1 Like

I’ll do some testing later and see which one is more optimized. (Will probably take a week because of school and other stuff)

Yeah but what’s that’s the difference between the two methods?

I’ll try my best to explain more of what I already said. Magnitude checks only between the position one and position two (using a radius), which returns the magnitude (a number) of those 2 position. GetPartBoundsInRadius checks EVERYTHING (from what I can tell) and too see if it’s in the radius, and then will return an array of the parts that are in the radius. The differences here is that magnitude checks 2 position and GetPartBoundsInRadius checks around itself to see if it’s in the radius (from what I can tell). As well what they return back. Hopes this help clear things up.

You think I could use this module to do something like a constant attack? That while the magnitude be below a certain number the script will take damage and compatible to few himanoids a the same time?

Yes, you can definitely use this module for tick attacks! You’ll just have to set the .hit to {Characters whom won’t be attack}.

newHitbox = hitboxManager:New(part,3,1}
for i=1,5 do
  newHitbox.hit = {Character} --Character won't be affected by the hitbox.
  task.wait(.5)
end
--pretty bad example of a 5 multi hit attack that the Character used that hits every .5 seconds

Sorry if this is a bad example. Also if this is not what you’re looking for I’m sorry!! Also sorry for the rushed response

2 Likes

I’m saying something like an aoe attack that Takes damage few times, only if the character is on the way.

I’m still confused on what you’re asking like a laser beam? Or like a slam kind of move that increases in size?

A attack that Takes a x amount of damage per a y time while you are inside the hitbox.

Then my horrible tick attack example is probably what you’re looking for if that’s the case. Should I make a tick attack feature?

I don’t think that’s what I say because you put a loop and i only now the player to take damage while he’s on the hitbox, and yes propably a new function like this will be usefull for other pepople also.

What if something like this happens
test
(the circle is the magnitude)

the hitbox will act normally ok. Besides that I don’t understand what you’re asking sorry!

what i mean is if you make the block tall enough and touch the bottom of the block it wont fire