#Hitboxes

1 messages · Page 1 of 1 (latest)

upper sorrel
#

So I want to create a good hitbox system for melee and ranged weapons, explosives, etc... How can I have a secure hitbox system that works good for all of these weapons? What should i use to achieve this?
Also the sript should be a modulescript but thats not a huge problem.
Also if there are already good modules, tell me.

smoky sandal
#

For swords I would use touch events

For punches I would use GetPartBoundsInRadius

For ranged weapons I would use touch but if you don't like physics based projectiles you can use raycast or shapecast

For explosives I would use GetPartBoundsInRadius

#

All hitbox detection relays on the clients position data so there all exploitable

You would need a antihack to keep track of the players characters position

upper sorrel
#

Uh, so there is a different ansver for every single weapon?

quick horizon
#

i just used Hitbox method in redplys combat videos

quick horizon
#

I see that it uses Vector3, how would you get the radius infront of a player's cframe

#

I typically use for example part.CFrame = char.CFrame + CFrame.new(0,0,-1)

smoky sandal
quick horizon
#

ah i was thinking it like how i made my hitbox for combat

quick horizon
smoky sandal
quick horizon
#

wym?

smoky sandal
#

What do you mean by combat

quick horizon
#

oh like just punching so far

#

i got animation events and then when the animation event is fired it will create a hitbox on the server

smoky sandal
#

OK I'm talking about the same thing

#

I would have a punch animation

#

And on the keyframe when the hand is extended out

#

Do a radius check around the hand

#

If it touching a object that can be hit

#

Send a remote event to the server

#

Server will do the sanity checks

#

Then deduct the health from the other object

quick horizon
#

ok

smoky sandal
#

if i was doing a sword

#

i would have a part welded to the sword

#

can be invisable

#

when i start playing the animation

#

i would connect a touch event

#

when the animation ends i would remove the touch event

#

if the touch event detects anything that it can hit a remote event is sent to server

#

and server does sanity checks

quick horizon
#

Right now what my combat module does is: check if the player is in cd before letting them punch, then sends a remote to the server saying who's punching, it then plays the animation on the server and then when the animation event is fired it will create the hitbox on the server where it then checks who is touching it and then does damage and then fires the knockback remote event

smoky sandal
#

and deducts the health

quick horizon
#

just a debounce, but i also got a stun table that prevents people from punching if they have been stunned

#

well, the debounce is local, the checks if they are in the stuntable is done on the server before the server then plays the animation

#

which then creates the hitbox etc

smoky sandal
#

did you know that the client can also play the animation and it will replicate to the server?

frozen bay
#

use raycats hitboxes for swords/melee weapons and use OBB overlap detection (or if you dont want to implement your own OBB system use getpartboundsinbox) if you want more of a hand-to-hand combat type hitbox.

quick horizon
#

like can localscripts get access to module scripts?

smoky sandal
#

not the servers modulescript but there own modulescript yes

quick horizon
#

ok

#

hm not sure how i can get a copy of the stun table on the client

#

i mean in a local script

#

for the validity

frozen bay
#

stun table? combat table? are you using sushimaster's combat system tutorial?

quick horizon
#

no redplys

frozen bay
#

does he make a module script that stores that type of data?

quick horizon
#

ye

frozen bay
#

rather than doing that, i think it is better to make other modules that do so. such as a cooldown module where you can do cooldown.new(player, move: string, duration: number)

#

and another function that is along the lines of cooldown.active(player, move: string): boolean

quick horizon
#

the cd is just a debounce

smoky sandal
quick horizon
frozen bay
#

checking cd on client does not really seem useful

#

perhaps it does eliminate some event calls but

smoky sandal
frozen bay
#

in the end the check on the client seems useless

#

yes, as suphi mentioned, attributes are a really good way to handle this dilema

quick horizon
#

this is how redplys did the stuntable

smoky sandal
#

also you dont want to play the punch animation on the clientside so you need a cooldown

frozen bay
#

yes, suphi is correct, and he has provided a great alternative

#

using attributes

#

they are replicated across cluent and server and so you can do client and server checks

quick horizon
#

ok

#

i will look into attributes

#

thanks a lot for everyones time

frozen bay
#

however, i dont think attributes can hold table values

smoky sandal
#

there is also a specil way

#

depending on how your stun works

#

its posible for the client to know it got stun with seeds and perlin noise

quick horizon
#

my stun just slows the player down

frozen bay
#

only?

#

it doesnt prevent usage of moves?

quick horizon
#

and makes them not do combat

smoky sandal
#

or with random.new(seed)

frozen bay
#

oh ok

frozen bay
#

suphi, is running a remote function more performant than performing a remote event call

quick horizon
#

the condition that plays it on the server checks if they been stunned ``` if not dictionary_handler.find(Character,"Stunned") then

smoky sandal
#

this video might teach you how to use seeds for the client to know if it got stun without using any network data

quick horizon
#

okay i'm going to save this conversation and try work on a smoother combat system

smoky sandal
quick horizon
#

thanks a lot @smoky sandal and @frozen bay

frozen bay
#

your welcome

upper sorrel
#

Okay so uhhhh

#

Is there any way for a single hitbox to handle all of the weapons I specified

smoky sandal
#

You would have to make a invisible part for explosions

#

But it would be easyer to use get parts bounds in radius

#

But that would be like tying one hand behind your back

upper sorrel
smoky sandal
#

i personally like to detect hits to the actual parts of the enemy

#

but if you want to make hitting easier by increasing the size of the hitbox you can add a invisible part on the enemy or you can add a invisible part on the sword etc..

upper sorrel
#

Doesnt using .touch suck

cunning vine
#

touched uses physics which runs at 240hz while the script runs at 60hz, this means if moved too fast in and out of the frame the touched event might detect it even though its not inside of it or did not move in the client.

spatial query & ray casting runs at 60hz whilst the physics runs at 240hz so this means if the projectile is fast enough these two might not detect it

#

also touched is basically free in terms of perfomance

#

@upper sorrel there are other threads talking about this you should take a look at them and read through

#

a problem with touched is that u can fire the event for other players so basically what that means is if ur a hacker in an obby game u can get a kill brick and move into other players and kill them

upper sorrel
cunning vine
#

if its some kind of false positive it'll ruin the player experience

upper sorrel
#

yeah but doesn't the player send the information of where the player should be and that hitbox on the same time right? So woulden't that not matter?

cunning vine
#

watch suphi's antiexploit video he goes over this

upper sorrel
#

alright

cunning vine
# upper sorrel alright

oh something suphi didnt go over which i didnt know about was if they fall they can exceed the "maxspeed" u set

#

u can use raycasting to see if they are actually walking/running or if they are falling* use a different "max speed"

upper sorrel
#

alright

upper sorrel
#

Okay so how i make a bomb with that

#

Like

#

What if the size is a variable

lethal quiver
upper sorrel
#

But doesnt ik have a unwanted visual effect and sound

cunning vine
#

or u could use touched

lethal quiver
upper sorrel
#

Yeah but i already got my answer

lethal quiver
#

And what you could do is try to make the explosion effect invisible by overriding it with another effect

wary bloom
#

Hitbox depend your game content, if you making game like Rogue Demon then use box hitbox.

lethal quiver
#

Yes it depends on your game

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

but read my message again

#

i said have the touch event in a localscript

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

and use a remote event to tell the server that you touched

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

its the same thing

#

all of it can be exploited

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

if you have the touch event on the server side or you use remote events you must always check the position of parts using a antihack

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

unless the part is anchored or you set the parts network owner to nil

#

then you dont need to use a antihack

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

yes it will be

#

because it takes time for position data to travel the internet to the other clients computers

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

jagged pier
#

One message removed from a suspended account.

jagged pier
smoky sandal
#
local hit = workspace:GetPartBoundsInRadius(hand.Position, 4, overlapParams)
jagged pier
#

One message removed from a suspended account.

jagged pier
smoky sandal
#

If you want to most optimal way

#

Let me see what options overlap params

#

1 option is to use collision groups

#

Another option is to put each characters hitbox in the filter and set to include

#

You don't want to generate the list every time you use the getparts function

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

You want to use characteradded and characterremoved to update the list

#

Another option if you want to detect hitting all parts of a character

#

Is put all the characters in a folder

#

And then set that folder as the filter

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

Yes

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

You do it on the server side

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
jagged pier
smoky sandal
#

Iv been programming since I was 12 years old

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

I'm almost 36 now

jagged pier
#

One message removed from a suspended account.

jagged pier
smoky sandal
#

its not good to load the animation every time

#

also its not good to conect to a connection inside another connection unless your disconnecting

#

you could have a memory leak

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

no

#

it would be better to just load the animation once

#

and only connect once

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#
local animation = script:WaitForChild("Animation")
local animationTrack = humanoid:LoadAnimation(animation)

animationTrack:GetMarkerReachedSignal("Hit"):Connect(function(paramString)
    local hit = workspace:GetPartBoundsInRadius(rightHand.Position, 4, overlapParams)
    if #hit == 0 then return end
    local character = hit[1]:FindFirstAncestorOfClass("Model")
    hitRemote:FireServer(character)
end)

userInputService.InputBegan:Connect(function(input, processed)
    if processed == true then return end
    if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
    animationTrack:Play()
end)
jagged pier
#

One message removed from a suspended account.

smoky sandal
#

also its better to do FindFirstAncestorOfClass on the client side

jagged pier
#

One message removed from a suspended account.

smoky sandal
jagged pier
smoky sandal
#

so it will be within around 10 to 20 studs

#

so its safe to just use the rootposition

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

so if the hit position is within 10 to 20 studs server will accept it

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#
local animation = script:WaitForChild("Animation")
local animationTrack = humanoid:LoadAnimation(animation)

animationTrack:GetMarkerReachedSignal("Hit"):Connect(function(paramString)
    local hit = workspace:GetPartBoundsInRadius(rightHand.Position, 4, overlapParams)
    if #hit == 0 then return end
    local character = hit[1]:FindFirstAncestorOfClass("Model")
    hitRemote:FireServer(character.Humanoid)
end)

userInputService.InputBegan:Connect(function(input, processed)
    if processed == true then return end
    if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
    animationTrack:Play()
end)
hitRemote.OnServerEvent:Connect(function(player, humanoid)
    if typeof(humanoid) ~= "Instance" or humanoid.ClassName ~= "Humanoid" then return end
    local position1 = antiHack.GetPosition(player.Character.Humanoid.RootPart)
    local position2 = antiHack.GetPosition(humanoid.RootPart)
    local magnitude = (position2 - position1).Magnitude
    if magnitude > 10 then return end
    humanoid:TakeDamage(10)
end)
#

somthing like this

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

i have a video showing how to make a basic antihack module

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

use

#

classname

jagged pier
#

One message removed from a suspended account.

smoky sandal
jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

smoky sandal
#

you can have variables in both the server and client

jagged pier
#

One message removed from a suspended account.

smoky sandal
#
local animation = script:WaitForChild("Animation")
local animationTrack = humanoid:LoadAnimation(animation)
local combo = 0

animationTrack:GetMarkerReachedSignal("Hit"):Connect(function(paramString)
    local hit = workspace:GetPartBoundsInRadius(rightHand.Position, 4, overlapParams)
    if #hit == 0 then return end
    local character = hit[1]:FindFirstAncestorOfClass("Model")
    hitRemote:FireServer(character.Humanoid)
end)

userInputService.InputBegan:Connect(function(input, processed)
    if processed == true then return end
    if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
    animationTrack:Play()
end)
local combos = {}

hitRemote.OnServerEvent:Connect(function(player, humanoid)
    if typeof(humanoid) ~= "Instance" or humanoid.ClassName ~= "Humanoid" then return end
    local position1 = antiHack.GetPosition(player.Character.Humanoid.RootPart)
    local position2 = antiHack.GetPosition(humanoid.RootPart)
    local magnitude = (position2 - position1).Magnitude
    if magnitude > 10 then return end
    local combo = combos[player]
    humanoid:TakeDamage(10)
end)

local function PlayerAdded(player)
    combos[player] = 0
end

local function PlayerRemoved(player)
    combos[player] = nil
end
jagged pier
#

One message removed from a suspended account.

smoky sandal
#

they should stay in sync for non hackers

#

they can go out of sync for hackers but it wont have any effect

jagged pier
#

One message removed from a suspended account.

#

One message removed from a suspended account.

jagged pier
#

One message removed from a suspended account.

smoky sandal
#

Don't use hit[1]

#

Loop the hit array and get all the players inside the array