Current Version: V.2.1 EXPERIMENTAL (6/05/2020)
- Experiencing inaccuracy problems? Try downloading an older version (pre 2.0) below to test.
- V2.0+ works best on the client-side, unlike older versions
Hi there! I just released a module that focuses on raycast hitboxing, so things like melee weapons will probably be the most useful. But feel free to let me know what other projects you will use this for!
RaycastHitboxShowcaseV2.rbxl (87.6 KB)
(do note that these places won’t be updated, so if this module gets an update, you have to do it)
(debug rays are by default on, so performance is decreased but will be smooth once you disable them)
I realized my post about raycasting hitbox has been blowing up lately in the scripting support category, so I decided to just compile any questions you guys have or if you want to have a go at it yourself, then this thread will be the hub for that. Let me know what improvements you want and I will be more than happy to implement it!
Original Post & Examples
A few years back, I’ve been intrigued by the design of MORDHAU and Chivalry since I wanted accurate hitboxing while making it simple to do across a variety of different weapon shapes and sizes. Here’s a timestamp of how MORDHAU did their hitbox for their swords which may prove to be helpful.
Warning: Does include realistic depiction of blood so please be aware before opening
It basically fires a ray from an attachment placed on the weapon every frame. Do note that the red lines are visualizations purposes only, they do not last that long.
I also made it so you can adjust the placements of where the raycasting starts via attachments so I can fit it on different weapon shapes easily without hardcoding it. Here is the same system but the attachments are spread out a little to compensate for larger hitboxes.
How To Use
It is very simple. More information can be read in the module itself. But basically, each attachment will be the points where the raycasting will shoot out of. By default, the module searches for attachments named “DmgPoint” (can be changed). We can do this:
and that’s it for the physical modifications! Now, I’m going to make an example script that is inside the model we just created that should work:
local RaycastHitbox = require(RaycastHitboxModule) local Damage = 10 local NewHitbox = RaycastHitbox:Initialize(script.Parent.Model) NewHitbox.OnHit:Connect(function(hit, humanoid) --- Do not put events on a loop, else you will memory leak and it will damage multiple times!! print(hit.Parent.Name) humanoid:TakeDamage(Damage) end) NewHitbox:HitStart() wait(5) NewHitbox:HitStop()
Don’t know if it works? Go into the module and turn on DebugRays and move the brick around to see if any rays are being drawn. Congratulations, you successfully created your own raycast hitbox thing! Now use this newfound knowledge on your own tools, models, etc.
Initialize function is recursive, so you can also call it on your own character and the script will find your attachments automatically.
Why Raycasting over Touched, Region3, etc… ?
I had a little thought process on the end of this thread, so you can check it out if you’re curious on why I opted to go for raycast.
- HitStart only hits a target once (so multiple rays don’t hit the same target). Call HitStop to reset this target pool so you can hit the same targets again.
- No multi-hit support (or Multi-hit support if PartMode is enabled)
- No Specific Team or NPC damage support (but there is an IgnoreList inside it)
- Wide objects requires a lot of attachments to be working correctly
I wrote this in a rush, but hopefully I’ve got everything down. Thanks for reading all.
Current Version V.2.1 EXPERIMENTAL (6/05/2020)
- Now uses new Raycast API!
- Removed Hitbox.ignoreList
- Added Hitbox.raycastParams
- OnHit now returns 3 arguments: hit, humanoid, raycastResults
V.2.0 EXPERIMENTAL (5/30/2020)
- Removed RaycastHitbox:DebugMode
- Removed HitStart([damage value]) argument
- Removed DontCheckForTransparency
- New HitboxObject:DebugMode
- Major Performance Improvements
RaycastHitboxV2.rbxm (8.4 KB)
V.1.53 BETA (4/03/2020)
- Updated some outdated API
- Clarified some troubleshooting steps
- Added a new troubleshooting question
- Added warnings whenever it detects rays are not being shown
RaycastHitbox153.lua (17.9 KB)
V.1.52 BETA (3/25/2020)
- Fixed LinkAttachment position errors
V.1.51 BETA (3/24/2020)
- Fixed SetPoints position errors (should now be as accurate as attachments)
- Credits to @Shurikanz for the find
V.1.5 BETA (3/23/2020)
- New HitboxObject:RemovePoints
- New HitboxObject:LinkAttachments
- New HitboxObject:UnlinkAttachments
V.1.3 & V.1.4 BETA (1/28/2020)
- Initialize should now return a hitbox and not nil
- Mild performance increases
- New Function: PartsMode (documentation is in the script)
1.21 BETA (10/30/2019)
- Removed RaycastHitbox:HitStart
- Removed RaycastHitbox:HitStop
DebugRays remade with constraints/attachments to help low-end devices
- Initialization performance improved
1.2 BETA (10/27/2019)
- New HitboxObject:SetPoints(Instance part, table vectorPoints)
- New RaycastHitbox:DebugMode(boolean true/false)
- Recursive now supports all instance types (no longer have to be a model!)
- Ignore list now automatically includes Terrain
1.1 BETA (10/24/2019)
- Deprecated RaycastHitbox:HitStart
- Deprecated RaycastHitbox:HitStop
- RaycastHitbox now returns HitboxObject
- New HitboxObject:HitStart
- New HitboxObject:HitStop
- New HitboxObject.OnHit:Connect(Instance part, Instance humanoid)
- New RaycastHitbox:GetHitbox(Instance model)
- Possible Issue - Heartbeat loop might not successfully disconnect when deinitializing, but happens sometimes (need confirmation)
- Initial Release
- Priority hitboxes, think Smash Tipper (Roy is still better though)
- Simple Example tool or model that uses this
Like this module? Please consider donating a little to support my future works!