How do raycast hitboxing modules work? (like ClientCast & Raycast Hitboxing)

Hello,

The title mainly says it all, I’ve delved into the source code behind ClientCast and Raycast Hitbox, but I’m still really confused about the details. Every time I search through their code, lots of stuff feels overcomplicated from what I’d assume they would do.

Sure, I get the surface-level stuff, but I’m wondering how you’re able to limit ray cast length, find the direction they’re supposed to be going, etc.

I’ve been hoping to try to make my own version from scratch to play with but finding resources past basic raycasting or projectile raycasting has been weirdly hard.

In essence, the code tracks the change in position for attachments between each frame, and raycasts from their previous position to the current. This means that raycast length is different based on how much they traveled during that frame, and the direction of travel.

2 Likes

workspace:Raycast takes 3 params. The first two are the start position and the displacement from the start point. The second gets called “direction” but it’s not, it’s the displacement from the start point because it’s length matters. Specifically the length indicates how far the raycast should go.

To raycast 3 studs to the right from a point p, do

workspace:Raycast(p, Vector3.new(3, 0, 0), params)

to raycast from p to another point q do

workspace:Raycast(p, q - p, params)

just keep working with vector math (e.g. by programming games) and you’ll get the hang of it sooner or later.

3 Likes