Raycast Hitbox 4.01: For all your melee needs!

Honestly this seems like a pretty efficient and useful module. Definitely will be using this for some projects in the future.

I also bought the donation so enjoy :wink:

4 Likes

V.1.52

Hi all, this version is just a minor fix for LinkAttachments, nothing too interesting.

But, wait, before you leave, I do have something interesting for folks who wants to try it out immediately without the need to code your own test tools or whatever.

Behold, the sample place!

(limited edition, link only available on the main OP, expires in the next 99 years)


It contains a modified Roblox LinkedSword, a damaging fan, and an impossible laser obstacle course. No @Shurikanz were harmed in the making of this film. I might have also stole the fan, so don’t use it for commercial work. Thanks.

11 Likes

Hahaha, this is great! I love it - thank you for this @TeamSwordphin :rofl:
Keep up the amazing work :smiley:

1 Like

Cool idea and well implemented. Maybe I’ll use that in my next game.

btw. who made you this cool character with the sword and the wings?
https://gfycat.com/enchantingdecentbeagle

Everything you see there is my own creation.

3 Likes

I created my own version of this module because I wanted to get rid of some complexity and use my own ray cast visualizer. However, I made something that might be of use for this module:

function CastDetector:GeneratePoints(resolution)
	local Increment = 1 / (resolution - 1)
	
	for alpha = Increment, 1 - (1 / resolution), Increment do
		local Attachment = Instance.new("Attachment")
		Attachment.Name = "CastPoint"
		Attachment.CFrame = self.Object.Bottom.CFrame:Lerp(self.Object.Top.CFrame, alpha)
		Attachment.Parent = self.Object
	end
end

It generates a line of attachments between a top and bottom attachment.

Before:
image

After:

The resolution argument specifies how many points in total including the top and bottom attachment.

Obviously this is only meant for normal swords and such.

11 Likes

definitely a cool module, I’ve used it a few times already!

1 Like

V.1.53

Due to the large amount of people DMing me lately about why their rays aren’t appearing, I’ve updated some of the outdated API and clarified the troubleshooting sections in the module. The module will now also scream warning messages when it detects an anomaly that prevents rays from being cast (for example, incorrect attachment names or transparent parts).

Functionality has not been altered. Hopefully this will help those that are still confused. If you are one of them, please consider DMing me or replying below so I can help.

4 Likes

Hello. I’m having trouble understanding why I would use Raycasting to detect hits rather than using the part.touched event in a tool. Can anyone explain the concept?

1 Like

I touched base on this topic a little on one of the threads I listed in the OP. But to summarize, I needed a way to have hitboxes that do two things: Be as accurate as possible while also maintaining adequate performance.

For simpler cases, like the classic Roblox sword, Touched is all you need. You don’t have to fiddle around making rays or region3s.

My games are based around extremely fast and fluid combat. Take this gif as an example:

Touched will not work with these kinds of animations because Touched relies on physics to register. If you played any games on Roblox where something flies really fast, sometimes you can see it phase or glitch right through solid objects when it should be bouncing back. Matured game engines like Unity and Unreal Engine still suffers from this. This is the same concept. Using raycasting will allow you to achieve hit detection velocity that is impossible with touched. It’s also, in my opinion, easier to work with then Touched.

In addition, if you are moving bricks with CFrame, Touched will not register them because they are not considered “physics”. Raycasting will fix this.

Region3s are another popular way for people to detect hits, even for Cframed parts, but they are static and not much you can do with them in terms of hitbox shapes.

Ultimately, there is no right or wrong answer to what you should use. Use whatever you feel is the most appropriate for your setup. Experiment, keep trying things out, and eventually, you will come to understand the limitations of each method. Raycasting for hitboxes suffers from resolution problems, meaning wider objects need fuller raycasting setups to achieve what Touched could already naturally do. Region3 is great but it requires modification for angles and lets in unnecessary parts.

All can be performance heavy if used wrongly, but in my testings, Raycasting is the easiest to get right.

19 Likes

I have a problem, the raycast won’t properly follow my model until after it gets a hit. After that, even deinitializing and reinitializing the hitboxes it still works.

EDIT 1: After further testing it seems that this only gets fixed attacking unanchored dummies, not anchored dummies or any player

2 Likes

How is the model getting created? Client or server sided? Might be a networking issue.

The model is added on character load, cloned from server storage.
Also, it seems that dying makes the raycast not follow the model again.

Is the raycasting done on the server as well? Are the animations of the model being played on the client or is the client sending its input to the server which makes the model play its animation?

The only thing that is on a local script is inputs which then fire remote events to the server, which then does everything else
animations are on the server as well

Try setting the model’s primarypart network ownership to the server.

PrimaryPart:SetNetworkOwner(nil)

The animations might not be replicating properly on the server since its close to the player. Are you using attachments or setpoints to create the raycasting?

attachments, I’ll try that then

Unfortunately did not work, any other ideas?

You can use #help-and-feedback:scripting-support showing all relevant code and rigging to get more in-depth help, to avoid clogging up this topic. (your problem is not really relevant to anyone else reading this topic)

3 Likes

Whats the best way to use this module for square hitboxes? Like a rock? I was thinking on adding attachments to every face of the rock but it dont seems be very good to performance.