What hit detection for beams-type of abilities?

Hi, I’m trying to find out what hit-detection method can I use for abilities like beams. What i mean by beams is:


There’s a game called Anime Battle Arena and it seems that their detection for beams is really good

Im not sure what to use, .touched, raycast, region3, et cetera

Using raycast is the best option.

But the thing is how can i make it so raycast can hit multiple people when many people are in the beam?

make a raycast from the start to the end of the beam and detect all people that the ray hit

Raycast stops at what it first detects, so if there’s 5 people in the beam, it will detect the first thing it hit, so how can I make it so it detects the other people behind it?

create multiple raycasts everytime it hits something create a raycast starting from the raycasts end position and going onward. you could use region 3 but its expensive and they might be used touched in ABA

You could use GetPartsInPart, which is like the new GetTouchingParts()

The spatial querry API (OverlappParams) might interest you.

Especially the function worldroot:GetPartsBoundsInBox()
(WorldRoot | Roblox Creator Documentation)


(WorldRoot | Roblox Creator Documentation)

These functions might be better suited for your need as they will return a table of all the parts found in the bounding box of the spatial querry based on the filter parameters, meaning you can detect multiple players and more in one go.

1 Like

Thank you, it’d make sense for them to use .touched but i’m wondering how it’s like so consistent, what debounce timer do you think they set it at ? or what approach for such a consistent detection with .touched, because i use .touched at like maybe 0.05 debounce per detection but it isn’t as consistent as ABA’s

I think they just check if it hits them then disconnect it when all the damage is done

You’ll want to use the Spatial Query API
More specifically, the WorldRoot:GetPartsInPart is what you want.

Here is some more detailed steps on what you’ll want to do:

  1. Decide a size for the hitbox/beam. Let’s say the size will be Vector3.new(5, 5, 20).
  2. After that, create a normal part on the server that has CanCollide to false and Anchored to true. Do not parent to workspace, it’s not necessary and will cause slightly more lag.
  3. Set the Size and CFrame of the hitbox part. The size should be the size you decided on in the beginning. The CFrame should be forward of the character’s HumanoidRootPart. To do this you can use the code below, and it will place the hitbox part perfectly infront of the character.
hitboxPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -hitboxPart.Size.Z/2)
  1. Use the WorldRoot:GetPartsInPart to detect, damage, and knockback entities.
  2. For the actual beam part, you’ll want to do this on the client. You’ll have to use RemoteEvents, in which you will send over the size you decided on before, and make the beam’s size the same as that. These are called Client Sided Effects, and they are so important for games with ablities/skills, as it will drastically reduce lag.
1 Like