#Method for hitbox detection

1 messages · Page 1 of 1 (latest)

pastel temple
#

What are some light but effective ways to make hitboxes? Right now my bright idea is to just simulate a bounding box with math, but im just curious what other methods people use

ebon sparrowBOT
#

studio** You are now Level 3! **studio

rain ridge
#

Hitbox:destroy()

lilac orchid
#

People tend to use raycasts as they're the most reliable

This library (which is the successor to Raycast hitboxes) may help: https://devforum.roblox.com/t/shapecasthitbox-for-all-your-melee-needs-v025/3624241

pastel temple
snow hollow
#

use spatial queries like workspace:getpartsinbox/sphere/etc

#

i'd suggest avoid using getpartsinpart to save creating an instance, unless the hitbox should last for several frames in which case you can also use .touch

#

or just use a spatial query every frame

#

up to you 🤷

pastel temple
#

what im currently doing is filtering through a list of parts tagged damagable, and checking if relevant parts are inside the box, im not sure if this is more or less efficient, i kinda feel like its less


function Punchingv1:Create_boundB(HumanoidRootPart: BasePart)
    local boundBoxSize = Vector3.new(6,6,5)
    local localboundBoxOffset = HumanoidRootPart.CFrame * CFrame.new(0,0,((boundBoxSize.Z/2)+0.7)*-1)
    -- Visualization (for debugging)
    local visual = Instance.new("Part")
    visual.Name = "PunchDebugBox"
    visual.Size = boundBoxSize
    visual.CFrame = localboundBoxOffset
    visual.Anchored = true
    visual.CanCollide = false
    visual.Transparency = 0.5
    visual.Color = Color3.fromRGB(255, 0, 0)
    visual.Material = Enum.Material.ForceField
    visual.Parent = workspace
    game.Debris:AddItem(visual, 0.2)
    return localboundBoxOffset, boundBoxSize
end
local boundB,BoundBSize = self:Create_boundB(hrp)
    local charHit = {}
    local damageables = collectionService:GetTagged("Damageable")
    for _, model: Model in pairs(damageables) do if model == char then continue end
        for _, part:BasePart in pairs(model:GetChildren()) do
            if part:IsA("BasePart") and damagablesParts[part.Name] then
                local partRelative = boundB:ToObjectSpace(part.CFrame)
                if math.abs(partRelative.X) <= BoundBSize.X and math.abs(partRelative.Y) <= BoundBSize.Y and math.abs(partRelative.Z) <= BoundBSize.Z then
                    table.insert(charHit,model)
                    break
                else
                    continue
                end
            end
        end
    end
snow hollow
#

that's absolutely, utterly insane.

pastel temple
#

😭

pastel temple
#

...

pastel temple
serene pebble
#

I started an M1 system today and I use a spatial query every frame like pyro said

Works well I suggest that

serene pebble
#

so i use a spatial query to add players into a list to do damage to them

real zephyr
serene pebble
#

when moving around if you only use a single frame it might be a bit hard to hit

i use a heart beat connection and a spatial query so say i move around alot it spawns hurtbox parts and stores any players it touches in the list once

then deals the damage

serene pebble
snow hollow
# real zephyr why not use a single frame for ur hit detection?

some attacks last for multiple frames like a wide sword swing will likely have multiple frames where it should be slashing for aoe radius, and it takes a few frames for the full swing to complete, so you'll need to do a query for every frame it should be damaging

#

or .touched

real zephyr
#

wouldnt it be better to do a stud buffer instead?

real zephyr
#

i also want to know the best method so im very open to your ideas

snow hollow
#

most people don't

snow hollow
real zephyr
snow hollow
#

that's not much of a compensation, it's just making the hitbox bigger

real zephyr
snow hollow
#

you can do some compensation with 2 hitboxes like that but it's complicated as to how you would actually use it

real zephyr
#

Deepwoken does this

snow hollow
#

i doubt deepwoken does this

#

it might do the compensator but it probably doesn't just broadly make the hitbox bigger

#

it's complicated why you might want to use 2 i'm not going to go into it right now

#

but it's not as simple as just a bigger hitbox

#

haven't played deepwoken so i can't say for certain but if they've done their homework they probably have a prediction system with rollback

#

compensator helps make this more accurate, less prediction errors. but again can't say for certain, just as much as you cannot

#

we don't have access to deepwoken source code.

real zephyr
snow hollow
#

i refuse to pay for it

real zephyr
snow hollow
real zephyr
real zephyr
snow hollow
#

correct, only client and shared code no server code

#

pretty obvious tell how they got it if theres no server code

#

if they do have server code then 🤷 they might've attempted to reverse engineer it based on client code

#

still huge job

#

why bother when you can just make your own

real zephyr
real zephyr
snow hollow
#

so they do it the tsb way then hehe

#

just completely ignore prediction and do everything on the server, input lag be damned

real zephyr
snow hollow
#

clearly

real zephyr
#

I would like some advice on prediction

#

Since I use server side hitboxes is there any benefit to me using cached positions in my checks

snow hollow
#

the full prediction pattern is very difficult to do

#

i'd suggest waiting for roblox to release their auroraservice instead of trying to make one yourself

real zephyr
snow hollow
#

for now

real zephyr
#

What do you do personally?

#

I mean you clearly have a lot of experience

snow hollow
#

i'll be adding the full prediction pattern to my framework

#

coz i don't have the luxury of 50 ping on 99% of roblox games

real zephyr
#

What type of predictions will you be using?

#

Mind spilling the secrets 👀

snow hollow
#

wat

#

there's only one kind

#

there are degrees of how much of the pattern you do tho

real zephyr
#

I'm confusing it with lag compensation I think

#

Networking is my weakest point

snow hollow
#

lag compensation and prediction go hand in hand but they are different concepts

#

lag compensation is usually called rollback netcode, prediction is where clients predict what the server is going to do before the server responds, sometimes this prediction is incorrect aka misprediction so you get jitter and other visual errors like that

#

like your character can teleport if big misprediction

snow hollow
#

if you've played any source engine games like csgo, gmod or tf2 you'll have experienced the full prediction pattern

real zephyr
#

I tried implementing predictikdn with my combat framework

#

Didn't go very well

snow hollow
#

yea you need s3~s4 tier skills to make it

#

very difficult

real zephyr
snow hollow
#

yep

#

packet loss, aka lost inputs will cause misprediction

real zephyr
#

Yes

snow hollow
#

or if your code is wrong it will mispredict as well

real zephyr
#

I assume that's where the usefulness of caching positions comes in for movement predictions

snow hollow
#

but under normal circumstances with minimal packet loss no one will notice

#

it's not just a cache ;o

#

much more involved than that

real zephyr
#

Yes ik what u mean

#

I considered doing predictions for my dashes but I realized it would take a lot more math than I thought

snow hollow
#

anyway i got things to do

real zephyr
#

Yeah man thank you for your time

serene pebble
#

alot of games inflate hitboxes to make it feel more responsive, take overwatch for example

#

personally though say im punching i would want hurtboxes to spawn that catch the player inside

#

you may see a game like brawlhalla do this and i think its alot better for games with alot of movement

pastel temple
#

So my current takeaway is to use spacial queries and look into rollback for hitboxes or prediction systems to compensate for ping, that sound about right?

serene pebble
#

basically dont bother with rollback until your S3-4 or roblox adds something to make it easier

#

theres probably an easier checklist to make sure your combat feels good

pastel temple
#

im not sure on optimization and preformance, i just want to see if im understanding how they work

serene pebble
#

if you want to give it a shot ofc

#

then the actual rollback

#

i think making it look and feel nice is also quite the challange

real zephyr
#

Is that a method that only client side hitboxes benefit from or also server side?

serene pebble
#

if youve ever played high ping and had a hit rejection thats why

#

oh apparently also OW call of duty and valorant

#

seems like the industry standard tbh

real zephyr
serene pebble
serene pebble
#

idk if there is any benefits for doing it client side

#

potentially responsiveness but it doesnt weight well against the cons

real zephyr
serene pebble
#

idk of any client specific rollback systems

real zephyr
#

in other words, if the client didnt use any prediction

serene pebble
# real zephyr in other words, if the client didnt use any prediction

if it didnt use any prediction imagine it like this

you have high ping and you shoot or hit someone

it wouldnt play any animation to begin with as it wont predict if you did or didnt hit them

then the server would calculate what should have happend rollback if need be and apply the hit

#

so it would look a bit off especially at higher pings

#

imagine shooting someone then say 0.3 seconds later you see the shot hear the shot and get the kill

#

i guess vise versa would be if it predicts against what you experienced you may feel cheated out
you saw your shot landed but the server said it didnt

real zephyr
#

I get that but in a timing sensitive system, its difficult to replicate this either way

#

i can see how this benefits input _> instant attack

serene pebble
#

ah like stringing a combo

#

yeah that would be very difficult to implement in a tight frame combo

real zephyr
#

with windups

#

not an instant attack

serene pebble
#

yeah i get what your saying
if street fighter and mortal kombat can use client side prediction and rollback then im sure its somehow possible

real zephyr
#

also we have to look at the perspective of all players not just the attacker

#

if the attacker uses client side prediction, the server will recieve the attack while the client's animation is already somewhat progressed

serene pebble
serene pebble
#

but thats more fair than the alternative

real zephyr
ebon sparrowBOT
#

studio** You are now Level 10! **studio

real zephyr
#

thats why client prediction for these systems is so rare

serene pebble
#

i mean if one of the biggest fighting games of all time is using prediction in their rollback they must have been able to implement it pretty well

real zephyr
#

im not saying prediction is useless for rollback, but it's pretty difficult to implement in this kind of scenario

#

especially with roblox's engine

#

perhaps if there methods to prevent replication from some client animations it would be infinitly more possible

serene pebble
#

well if pyro fire thinks roblox will add some service to make it easier maybe in due time itll be possible for your average developer

real zephyr
serene pebble
#

honestly

if your new to it and just want a working game i think theres more pressing matters that can make your combat feel better easier
lower hanging fruit

if you want to specifically for the fun or experience or have made combat games before and want a step above go for it

real zephyr
#

I make the hitbox slightly bigger than visuals so its more consistent too

#

Im also considered about the scalibility for my polling:

RunService.Heartbeat:Connect(function()
    for character, rollCharacter in pairs(self.HRPCache) do
        rollCharacter:Record()
    end
end)
#

this polls the positions of the roots

serene pebble
serene pebble
#

so 500 ms ago is quite unrealistically needed as idk anyone who constantly has to play on 500ms

#

i think the heavy top end that should be accounted for is 300

#

so you need say 350ms worth of history saved then after that remove it

#

or your table will grow and grow

#

you could try storing only the root

  • cframe
  • velocity
  • maybe rotation or a look vector
#

instead of the entire character

#

also you dont need to store every frame

#

i would try find a nice balance where its accurate but your not oversaving data whatyou dont need to

real zephyr
real zephyr