Current Version: 1.21 BETA (10/30/2019) – Always backup your module before updating!
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!
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:
Currently the script only supports Model type instances, so we will just group the part with itself: V.1.2 now supports all instance types
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 (relevant to above)
- 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.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
- Make rays between two attachments